Software Development
How software is planned, built, tested and kept working: the life cycle and its three models, structure charts and state-transition diagrams, the three kinds of error, the methods of testing and how to choose test data, and the three kinds of maintenance.
Why software is built in stages
Software is built in planned stages, and each stage produces something clear before the project moves on.
A program development life cycle is a planned series of stages for building a program.
Why use one? The project is easier to manage, plan and cost. Each stage ends with clear deliverables: the documents or code it must produce.
| Stage | What happens |
|---|---|
| Analysis | find out exactly what is needed: the developer discusses the requirements with the customer and writes them down |
| Design | decide how the program will work: a structure chart, pseudocode or flowcharts, an identifier table, the data structures, the interface and a test plan |
| Coding | write the program, usually in an IDE |
| Testing | run the test plan and fix the errors found |
| Maintenance | change the program after it is released |
The waterfall model
In the waterfall model each stage is finished before the next starts, like water falling down steps.
In the waterfall model, the stages happen in order:
- Each stage is completed before the next one begins.
- The output of one stage is the input to the next.
- If more work is needed, the team goes back up to an earlier stage.
| Benefits | Drawbacks |
|---|---|
| the budget and the finishing date are easier to predict | the customer sees working software only near the end, with no early version to try |
| all the requirements are found before coding starts | a change or a mistake found late means going back to finished stages, which is slow and difficult |
Remember:Waterfall suits a project whose requirements are clear and will not change.
The iterative model
The iterative model builds a basic working version first, then improves it again and again.
In the iterative model:
- A basic working version is built first.
- It is improved in repeated cycles, called iterations.
- Each iteration goes through design, coding and testing.
- The customer gives feedback on each new version.
| Benefits | Drawbacks |
|---|---|
| working software appears early | the total time and cost are harder to estimate |
| a change only affects the current iteration, so less finished work has to be redone | the customer must give time regularly |
| the customer is involved all the way through, so the result matches what they need |
Rapid application development, and choosing a model
RAD builds quick prototypes for users to try; pick the model that fits the project.
Rapid application development (RAD) builds prototypes quickly, with little planning at the start. A prototype is an early, working model of the system.
- Teams often build different modules at the same time.
- Users try each prototype and say what to change.
| Benefits | Drawbacks |
|---|---|
| fast delivery | users must be available all the way through |
| users are closely involved, so the system does what they need | the time and cost are hard to estimate |
| documentation is often left out |
Choosing a model:
| Choose | When |
|---|---|
| waterfall | the requirements are clear and fixed |
| iterative | a large project is built in smaller steps |
| RAD | time is short, the requirements may change, and users need a prototype early |
Structure charts
A structure chart shows a problem split into modules, and the parameters passed between them.
A structure chart shows how a problem is split into modules.
- Each module is a box.
- Lines join a box to the modules it calls, left to right in calling order.
| Symbol | Means |
|---|---|
| labelled arrow pointing down | a value passed in |
| labelled arrow pointing up | a value passed back |
| arrow both ways | BYREF |
| an open circle | data |
| a filled circle | a Boolean flag |
| curved arrow across lines | repeated calls |
| diamond | only one of the modules is called |
Each box becomes a header in the code.
Exam:A module that passes back one value, and nothing both ways, is a FUNCTION. The others are PROCEDUREs.
PROCEDURE ProcessResults() FUNCTION GetMark() RETURNS INTEGER FUNCTION IsValid(Mark : INTEGER) RETURNS BOOLEAN PROCEDURE UpdateStats(Mark : INTEGER, BYREF Total : INTEGER, BYREF Passes : INTEGER) PROCEDURE ShowResults(Total : INTEGER, Passes : INTEGER)
State-transition diagrams
A state-transition diagram shows how a system moves from state to state as inputs arrive.
A state-transition diagram documents an algorithm whose next action depends on what has already happened.
- Each state is a circle.
- An arrow from one state to another is a transition. It is labelled
input | output: the input that causes it and, after the bar, any output. - An arrow marked START points at the first state.
In this lock screen, an input with no arrow leaving the current state changes nothing. The same information as a table:
| Current state | Input | Output | Next state |
|---|---|---|---|
| LOCKED | Correct PIN | Open home screen | UNLOCKED |
| LOCKED | Wrong PIN | Show "Try again" | ONE_WRONG |
| ONE_WRONG | Correct PIN | Open home screen | UNLOCKED |
| ONE_WRONG | Wrong PIN | Show "Try again" | TWO_WRONG |
| TWO_WRONG | Correct PIN | Open home screen | UNLOCKED |
| TWO_WRONG | Wrong PIN | Show "Wait 30 s" | BLOCKED |
| BLOCKED | 30 s pass | (none) | LOCKED |
| UNLOCKED | Power button | Turn screen off | LOCKED |
Exam:Be ready to turn a table into a diagram, and a diagram into a table.
Three kinds of error
Syntax errors stop translation, run-time errors crash the program, and logic errors give wrong answers.
| Error | What it is | Example | Who finds it |
|---|---|---|---|
| Syntax error | breaks the grammar rules of the language | a missing ENDWHILE; a misspelt keyword | the translator reports it; the code cannot be translated until it is fixed |
| Run-time error | happens while the program is running: it tries an illegal operation, and it crashes or freezes | dividing by zero; an index outside an array | it shows up when the program runs |
| Logic error | the program runs to the end but gives the wrong result, because the algorithm is wrong | a wrong starting value; < where <= was needed | nothing reports it, so only testing finds it |
Example:In the code below, if the first mark entered is -1, Count stays 0. Then Total / Count divides by zero: a run-time error.
DECLARE Total : INTEGER DECLARE Count : INTEGER DECLARE Mark : INTEGER Total ← 0 Count ← 0 INPUT Mark WHILE Mark <> -1 Total ← Total + Mark Count ← Count + 1 INPUT Mark ENDWHILE OUTPUT "Marks entered: ", Count OUTPUT "Average: ", Total / Count
Finding errors: dry run, walkthrough and the debugger
Find faults by hand with a dry run or walkthrough, or with the IDE's debugging tools; good design avoids them.
Faults can be exposed before and after coding.
| Method | How it works |
|---|---|
| Dry run | work through the code by hand with test data, writing each value in a trace table |
| Walkthrough | the programmer takes others through the code or design, line by line, so that they spot faults |
| Breakpoint (IDE) | stops the program at a chosen line |
| Single stepping (IDE) | runs one line at a time |
| Watch (report) window (IDE) | shows the variables' current values |
The IDE features come from System Software (5.2). They are used to locate errors.
Remember:Avoid faults in the first place with good design, modules, meaningful names and tried and tested library routines.
White-box and black-box testing
Black-box testing checks WHAT the program does; white-box testing checks HOW, path by path.
| Black-box testing | White-box testing | |
|---|---|---|
| Looks at the code? | no | yes: the tester reads the code |
| Tests | what the program should do | how the program does it: its internal logic |
| Chooses data so that | outputs can be compared with the expected outputs for chosen inputs | every path through the code runs at least once |
Watch out:A program can pass every black-box test and still have a path that no test ran.
Example:In the ticket program, ages 3, 12 and 30 run all 3 branches. But none is 65 or over, so the Age >= 65 half of the OR is never TRUE. Add 70 to test it.
Stub, integration, alpha, beta and acceptance testing
Each kind of testing has its moment: modules with stubs, then together, then in-house, real users, and the customer.
Stub testing lets a module be tested while a module it calls is unfinished or does not work. That module is replaced by a stub: a simple dummy. It returns a fixed value, or outputs a message to show it was called.
The other kinds, in order:
| Testing | When, and by whom | What happens |
|---|---|---|
| Integration testing | once each module works on its own | the modules are tested working together |
| Alpha testing | before release, in-house, by the developer's own testers | the program is tested inside the company |
| Beta testing | with a nearly finished version, by a small group of real users outside the company | the users report faults and suggest improvements |
| Acceptance testing | with the finished system, by the customer | it shows that the system meets the requirements |
PROCEDURE ShowResults(Total : INTEGER, Passes : INTEGER) OUTPUT "ShowResults called with ", Total, " and ", Passes ENDPROCEDURE
Test data and the test plan
A test plan lists every test with its data and expected result, using normal, abnormal, extreme and boundary data.
A test strategy, drawn up at the design stage, sets out which methods of testing will be used.
A test plan lists each test: its number, what it tests, the test data, the type of data and the expected result.
| Type | Meaning | Expected |
|---|---|---|
| Normal data | well inside the range | accepted |
| Abnormal data | outside the range, or the wrong type | rejected |
| Extreme data | the largest and smallest values still accepted | accepted |
| Boundary data | the last value accepted and the first rejected, on either side of a limit | one accepted, one rejected |
Example:A test plan for whole numbers from 13 to 17.
| Test | Data | Type of data | Expected result |
|---|---|---|---|
| 1 | 15 | normal | accepted |
| 2 | 13 | extreme and boundary | accepted |
| 3 | 12 | boundary and abnormal | rejected |
| 4 | 17 | extreme and boundary | accepted |
| 5 | 18 | boundary and abnormal | rejected |
| 6 | "fifteen" | abnormal | rejected |
Exam:The 9618 syllabus names extreme/boundary as one type. Test both sides of every limit.
Maintenance, and changing a program you did not write
Maintenance keeps changing a program after release: to fix it, to fit a changing world, or to make it better.
Maintenance goes on after release, because faults are found, the world around the program changes, and users want more.
| Kind | Why | Example |
|---|---|---|
| Corrective maintenance | fixes faults found after release | a crash on some input |
| Adaptive maintenance | something around the program changed | new hardware, a new operating system, a new law, or new requirements, such as a new task the users need |
| Perfective maintenance | improves a program that already works | it performs better, for example faster |
To amend a program you did not write:
- Dry-run it first, to understand it.
- Make one change at a time.
- Retest it with the old test plan, as well as new tests.
- Click the stages below in the order they happen.
KEY TERMS
CHECK YOURSELF
1.Testing that ignores the internal code and checks only inputs against outputs is:
2.The software is changed because a new law requires it. Which maintenance is this?
3.What is the main weakness of the waterfall model?
4.ShowResults has not been written yet, so a simple module that only outputs a message stands in for it while the rest is tested. What is this?
5.The average program is given -1 as its first input, so it divides by zero and crashes. What kind of error is this?
6.A club accepts whole-number ages from 13 to 17. Which pair is boundary data for the upper limit?
7.On this lesson's lock screen, the phone is in the state LOCKED and receives an input with no arrow leaving LOCKED. What happens?