G3 Computing Textbook Chapter 08
G3 Computing Textbook Chapter 08
08 Software Engineering
316
317
8.1 Stages in Developing a Program
LEARNING OUTCOMES
2.6.1 Understand and describe the stages in developing a program: gather requirements, design
solutions, write code, test and refine code, deploy code.
ER MS
Software engineering is the process of designing,
creating, and maintaining software applications. In
KEY T
general, there are five stages in developing a program. Software Engineering
The process of designing, creating, and
This is a version of the traditional “waterfall model” maintaining software applications
of software development where progress flows
through multiple stages in a sequential manner and
each stage is completed before moving on to the next
stage, just like how a waterfall flows downward in a
single direction.
!"#$%&'(%)*+&%,%-#.
/%.+0-'123*#+2-.
4&+#%'526%
7%.#'8'(%9+-%'526%
/%:32;'526%
318
8.1.1 Gather Requirements
The goal of this initial stage is to determine the nature of the problem, why a program is needed and what
the program is expected to do. If this stage is not performed properly, it is likely that any program that is
developed will not be as useful as intended. Some of the tasks that can be done during this stage:
• Interviewing the intended audience of the program to understand the nature of the problem or
their expectations
• Specifying the complete set of inputs that is necessary for the problem and how the inputs can
be supplied to the program being developed
• Specifying the complete set of outputs that is necessary for the problem, any requirements the
output must meet and the format for the output
Suppose Siti is required to develop a program to manage the loan records and check the availability of
books at the school library. She interviews the librarians in her school to understand why a program is
needed and what the program is expected to do. They give the following responses:
From the information that she has gathered, Siti concludes that the program would need the following
inputs and output shown in Table 8.1. She has also given each input a descriptive name to work with.
319
Input Expected Output
Table 8.1 Input and output requirements for the book availability problem – Test Case 1
A good way to check whether the program’s requirements are understood correctly is to write test cases.
This is also a good opportunity to solve simple examples of the problem manually for the next stage. Siti
thus prepares two test cases under normal conditions:
320
She then prepares a test case under error conditions where the book is not found:
• search: “Resilience”
Siti also prepares additional test cases to cover boundary conditions such as having empty inputs, but for
simplicity we shall omit these test cases from the following discussion.
U
DID YO
N O W ?
K
For user interface requirements that may not be expressed easily as test
cases, a sketch or mock-up of the final product (without any actual code)
can be another useful communication tool for developers to visualise
and understand the desired features and behaviour of the software.
After gathering and refining the required inputs and outputs of the program, the next stage is where
the skills of decomposition and generalisation are used to plan out a solution. The goal of this stage is
to consider the options available before any code is written, and to choose an algorithm based on the
resources available (such as manpower and time). Some of the tasks that can be done at this stage:
• Manually solving different simplified examples of the problem and generalising the steps needed
to produce the required output
• Trying different ways to break down the problem into smaller parts such that the intended output
of each part gets closer and closer to what is needed to solve the problem
• Comparing the problem (or its smaller parts) to other problems that have been solved before and
identifying which algorithms can be used
• Estimating the amount of effort needed to write the code or the time needed to complete the
algorithm before making a definite choice
• Planning possible algorithms using flowcharts
321
U
Siti notices that she can DID YO
decompose the problem
O W ?
into three distinct tasks of
obtaining input, searching K N
through the list of book
titles and, finally, generating Often, existing software or Python modules that solve significant parts
output of whether the of the problem are readily available online so it will not be necessary to
requested book is available. reimplement the relevant algorithms. Finding and using such resources,
She illustrates this using a if allowed by their license (see Chapter 12), can greatly reduce the
simple flowchart shown in amount of new code that needs to be written in the next stage.
Figure 8.3:
START
OUTPUT result
STOP
She notices that the task of reading comma-separated values from a file can be further decomposed
into the tasks of reading a file and splitting its lines based on a delimiter. She also notices that the task of
searching for the book title is similar to the task of finding the location of a value in a list. From there, she
can adapt algorithms that she is already familiar with to complete the task.
322
START
INPUT availability.txt as ƒ
availability = []
No
All items in lines line = next unprocessed item in lines
processed?
Yes
Split line by “,” delimiter and insert split
INPUT search values into availability
No
All items availability record = next unprocessed item in
processed? availability
Yes
No
Is search == record [0]?
Yes
OUTPUT results
STOP
Siti decides that this planned solution is feasible and moves on to the next stage.
323
8.1.3 Write Code
In traditional program development, the code for the final program is written only after the first two
stages of gathering requirements and planning solutions are completed. This minimises the possibility of
producing code based on incomplete requirements or inefficient algorithms that would eventually need to
be discarded. The goal of this stage is to write code that performs the algorithm as planned in the previous
stage as efficiently as possible.
One possible way for Siti to write her code would be:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
U
DID YO
KNOW?
Instead of writing code from scratch, generative artificial intelligence services, such as GitHub
Copilot, ChatGPT and Google Gemini, can generate useful code based on an English description
of the problem to be solved. For best results, decomposition should be used to break the problem
down into simpler parts first as such services may not work well for overly complex or uncommon
problems.
Although useful, be aware that the code generated from such services may not always be correct
and there are ethical concerns as these services typically use code written by authors who may
not have explicitly consented to the use of their code in this way. In addition, using these services
and presenting the code that is generated as your own work would be considered plagiarism.
These and other concerns with the use of Artificial Intelligence are discussed further in Chapter 14.
324
8.1.4 Test and Refine Code
After the initial code is written, the resulting program is likely to require further refinement. Some possible
reasons for this:
• The programmer may have made mistakes in translating the planned algorithm into code or may have
forgotten to perform input validation. For example, the programmer may have made a syntax error or
forgotten to check for invalid input. These are relatively minor errors that usually would not require
major rewriting of code as simply correcting the syntax error or adding an if statement would usually
be sufficient to correct the program.
• The solution-planning stage may not have been performed properly, resulting in an unsuitable or
incomplete algorithm. For example, the chosen algorithm may give the correct answer for only some
combinations of inputs and not for other (valid but perhaps less common) combinations of inputs.
Depending on how serious the mismatch is, it may be possible to keep most of the written code and
simply make refinements. Otherwise, it may be necessary to discard the written code and redo the
evaluation of algorithms.
• The requirement-gathering stage may have been incomplete, resulting in code that does not address
the users’ needs. Depending on how serious the mismatch is, it may or may not be possible to reuse
most of the written code.
U
Testing is the process by which DID YO
KNOW?
these and other imperfections
are uncovered. For the first two
points, this is done by running the
code through the test cases that
may have been written during the To detect the possibility that the program may not actually
requirement-gathering stage to address the users’ needs, after passing the prepared test
evaluate whether the written code cases, user acceptance testing may also be performed. In
adequately satisfies the gathered user acceptance testing, members of the program’s intended
requirements and is ready to be audience use early versions of the program and provide feedback
used. to the developers. If the testing is done at the developer’s site,
this is called alpha testing. If the testing is done externally in
Siti runs the program through the the user’s environment, this is called beta testing. This process
test cases one by one, comparing of involving eventual users of the program early ensures that
the program’s output with the requirements gathering is performed properly and helps to
expected output: avoid any problems later when the code is deployed.
325
→ Input Expected Output →
So far, the output of Siti’s program has matched the expected output, so the program seems to be
functioning as intended. However, she proceeds to run the next test case that searches for the name of a
book which is not in the library collection.
• search: “Resilience”
---------------------------------------------------
NameError Traceback (most recent call last)
Input In [1], in <cell line: 15>()
12 result = record[1]
14 # Output
---> 15 print(result)
326
Now, Siti notices a bug. When the user enters the name of a book that does not exist in the library, her
program generates an error instead of producing the expected output “Book Not Found”. (If you are
running the test case for yourself, you may not get the error of an undefined variable if you ran any previous
test cases in the same Jupyter notebook. Instead, the output from the last test case that is still stored in
result will be displayed, which still fails the test case.)
Siti studies her program carefully and realises that she did not consider this special case. Fortunately, she
can resolve this by initialising the value of result to “Book Not Found”. Her refined code is shown in Figure
8.6:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
• search: “Resilience”
327
Siti then continues to run the program on the remaining test cases and makes further modifications to fix
bugs until all test cases are passed.
U
DID YO
KNOW?
In larger projects with multiple developers, code is usually kept in a version control system,
such as Git, that allows developers to easily track, compare and combine changes from multiple
programmers. Version control systems also allow for previous versions of code to be recovered
easily if any modifications need to be rolled back.
With the code tested and refined, this is the stage where the program is actually “rolled out” and used by
its intended audience. Some of the tasks that can be performed under this stage:
Siti deploys her code by installing Python in the library’s computer and copying the program over. She
organises a training session to teach the librarians how to use the program and gathers their feedback after
the first day of use. She receives the following comments:
It seems that while Siti’s program meets the requirements, it can still be improved in terms of usability and
speed. To make these improvements, it may be necessary to perform a review and repeat the five stages
starting from the requirements gathering stage.
328
QUICK . 1
C K 8
CHE
1. Write a short description for each of the five software development stages (i.e., gather requirements, design
solutions, write code, test and refine code, deploy code).
2. Describe two problems that might occur if the initial requirements-gathering stage is not performed properly.
3. For each of the following activities, identify at which stage of software development the activity is most likely
to occur in:
a) Translating an algorithm to a computer program.
b) Editing the program to fix a bug.
c) Asking users to describe what they want for the program’s output.
d) Installing the program on a user’s computer.
e) Deciding on an algorithm that would produce the desired output.
LEARNING OUTCOMES
2.6.2 Recognise that the sequence of software development stages may not be linear, and the use
of iterative development may sometimes be more appropriate.
These scenarios highlight a weakness of having a strict sequence of stages in that requirements often
change in practice, but a linear approach makes it difficult to go back and make changes to earlier stages.
Ideally, some flexibility is allowed such that if issues are identified at a later stage, it’s possible to go back
to a previous stage and make adjustments.
Hence, sometimes the use of alternative software engineering methodologies that allow for iterative
development and blending of the different stages may be more appropriate. Two such methodologies are
Agile Development and Test-Driven Development.
329
8.2.1 Agile Development
Although “agile” is a broad term that encompasses a range of practices, in general software developers
who practice agile development break down a large project into smaller increments so feedback and
changes to requirements can be integrated continuously.
:%-#;",9
'%<*,%;869% :%-#;",9
'%<*,%;869% :%-#;",9
'%<*,%;869%
3%=76>
869% 1&*#% 3%=76>
869% 1&*#% 3%=76>
!"#$%& 869%
!"#$%&
869% 869% 1&*#%
869%
!"#$%&
Figure 8.7 Agile is an iterative process where smaller versions of the five stages take place for each sprint
Unlike the traditional model where developers complete writing code before testing code, in Test-Driven
Development (TDD), test cases are run regularly, and code is written incrementally to pass each test. Many
aspects of this methodology, such as writing test cases before writing code and testing incrementally,
already reflect some of the recommended practices in this textbook.
330
U
In TDD, each time new functionality is DID YO
?
KNO W
implemented, three steps are followed.
1 2 3
Write Test Cases Write Code Tidy the Code
The test cases should specify The goal for this step is to After the test cases pass,
the intended behaviour of write the minimum amount developers can improve
the new functionality and will of code needed to pass all the code’s organisation,
initially fail because code has the test cases. This is to readability, and efficiency
not been written yet. discourage implementing without changing its
functionality for which test functionality. This step
cases have not been written ensures that the code remains
yet. clean and maintainable.
QUICK . 2
C K 8
CHE
1. For each of the following statements, state whether it is a valid reason as to why an iterative process may be
more appropriate than following the five stages of software development in a strict order.
a) Users may not know what they truly want until they have experimented with an early version of the product.
b) New and unexpected requirements may arise midway through development.
c) The time required to go through the five stages is not significant and so it is not costly to iterate through them
repeatedly.
d) The risk of having an entire project fail is reduced as working software is produced incrementally.
e) The program can be deployed more quickly as testing and refining code may be skipped after the first
iteration.
f) It is easier for developers to satisfy a small set of requirements at a time over multiple iterations than to
satisfy the entire project’s requirements all at once.
331
W
REVIE
E STI ON
Q U
1. In some versions of the traditional model, test cases are not used for requirements gathering and are
prepared only after the project’s code is written. Suggest one possible disadvantage of this approach.
2. You have been asked to develop a direct replacement for an existing program with no change in behaviour
other than the programming language used. The requirements for the current program are already fully
documented and the replacement program must be completed within a fixed timeline. Interaction with the
program’s eventual users is also limited to two short periods at the start and end of the project.
Suggest two reasons why an iterative approach may not be appropriate in this scenario.
3. While training teachers in the code deployment stage on how to use a new program for classroom
management, a developer encounters some problems caused by previous stages of software development
not being performed properly. Suggest which stage is most likely to be at fault for each problem and explain
why:
ANSWER
332
ANSWER
3. a) Write code
b) Test and refine code
c) Gather requirements
d) Deploy code
e) Design solutions
Pg.332-Review Question
1. Any two of:
• Higher chance of misinterpretation or misunderstanding of requirements. Test cases are more explicit than
trying to describe requirements in words and they help to ensure that there is a shared understanding of the
requirements by both developers and users.
• Higher chance of omitting requirements, especially for input data under error and boundary conditions.
The guideline that test cases must cover normal, error and boundary conditions helps to ensure that the
requirements under these conditions are properly considered.
333