Producing robust programs
Validation and authentication, code that is easy to maintain, the kinds of error, and choosing test data that proves a program works.
Watch the lesson
Every point below, worked through in one video, and each point links straight to its own part.
Learn
Producing robust programs, explained point by point
Everything the GCSE specification expects you to be able to do, and how to actually do it - the same lesson a signed-in student studies from.
Explain defensive design: anticipating misuse and authenticating users
A robust program keeps working whatever the user does. Defensive design means thinking in advance about what could go wrong: someone typing letters where a number is expected, leaving a box empty, or trying to reach something they should not. Authentication checks that users are who they say they are, usually with a username and password, before letting them in. A simple routine compares what was typed with the stored details and limits the number of attempts.
Use input validation
Validation checks that data is reasonable before the program uses it. A range check makes sure a number lies between two limits. A length check counts the characters. A presence check makes sure something was entered at all. A format check, which Edexcel calls a pattern check, makes sure the data has the right shape, such as a postcode, and a type check makes sure it is the right kind of data. Validation cannot tell whether data is true: an age of 61 typed in place of 16 passes a range check. Eduqas also asks for verification, such as typing an email address twice to catch a slip.
Write code that is easy to maintain
Programs are read and changed long after they are written, often by someone else. Comments explain what a section is for. Meaningful names say what a variable or subprogram holds or does. Indentation shows which lines belong inside a loop or a selection. Subprograms break the work into parts that can be understood and changed one at a time. Each of these makes it quicker to find a fault and safer to change the code.
Identify syntax errors, logic errors and runtime errors
A syntax error breaks the rules of the language, and the translator reports it before the program runs. A logic error does not stop the program, but the result is wrong, so it can only be found by testing. Edexcel and Eduqas also name the runtime error, where a program that started correctly stops while it is running, for example on dividing by zero or reading past the end of a list. Eduqas adds rounding and truncation errors, where a number loses accuracy as it is stored.
Explain the purpose of testing, and the difference between iterative and final testingOCR only
Testing shows whether a program does what it should and finds the errors so that they can be fixed. Iterative testing is done while the program is being written: each part is tested as it is finished, the faults are fixed, and it is tested again. Final testing, also called terminal testing, checks the whole program at the end of development. OCR examines these two terms. Leaving all the testing to the end makes faults far harder to track down.
Choose suitable test data
Good test data covers every kind of input. Normal data is what a user would be expected to enter and should be accepted. Boundary data sits at the very edge of what is allowed, such as 0 and 100 for a mark out of 100, and is where mistakes with less than and less than or equal to show up. Erroneous data is the wrong type, such as a word where a number is needed, and should be rejected. OCR also separates out invalid data, which is the right type but outside the limits, such as 101. Eduqas calls the three kinds typical, extreme and erroneous. Edexcel asks for suitable test data without naming categories.
Use a test plan and refine a programOCR, Edexcel and Eduqas only
A test plan is a table written before testing. Each row gives the test data, the reason for the test and the result expected. Running the tests adds the actual result, and any row where the two differ points at a fault. Fixing the fault and running the plan again is refining. OCR and Eduqas ask for test plans. Edexcel and Eduqas also ask you to evaluate a program: whether it meets its requirements and how it could be made more efficient.
Producing robust programs key terms
The words the specification and the mark schemes use, each defined the way an examiner wants it.
- Defensive design
- Designing a program to cope with unexpected or incorrect input without crashing.
- Authentication
- Checking that a user is who they claim to be, for example with a username and password.
- Validation
- An automatic check that data entered is reasonable and follows the rules set for it.
- Range check
- A validation check that a value lies between a lower and an upper limit.
- Presence check
- A validation check that a value has been entered and the input is not empty.
- Maintainability
- How easily a program can be understood, corrected and changed by a programmer.
- Iterative testing
- Testing each part of a program during development, then fixing and testing again.
- Final testing
- Testing the complete program at the end of development, also called terminal testing.
- Boundary data
- Test data at the very edge of the range a program should accept.
- Erroneous data
- Test data of the wrong type, which a program should reject.
- Test plan
- A table listing the tests to be carried out, the data for each and the result expected.
Common mistakes in Producing robust programs
The slips that cost marks year after year, and what to do instead.
Saying validation checks that data is correct
Validation checks that data is sensible and allowed. It cannot tell whether it is true, so a wrong but reasonable value still passes.
Giving boundary data that is not on the boundary
For a range of 1 to 10 the boundary values are 1 and 10 themselves, with 0 and 11 just outside.
Mixing up invalid and erroneous data on OCR
Invalid data is the right type but breaks the rules, such as 150 for a percentage. Erroneous data is the wrong type altogether.
Writing a test with no expected result
Every test needs the data, the reason for the test and the result you expect, so that the actual result can be compared.
Listing maintainability features without saying how they help
Say what each one does for the next programmer, such as comments explaining what a section is for.
Practice
Try a Producing robust programs question
A GCSE-style original question from this topic. Have a go before you open the working - deciding on an answer first is what makes the working stick.
Answer: 15 normal, 31 boundary, June erroneous
15 is a typical valid day, 31 is the valid value at the top edge, and June is text, the wrong type.
- 15 is a sensible valid day, so it is normal data.
- 31 is valid but on the very edge of the range, so it is boundary (extreme) data.
- June is text where a number is expected, so it is erroneous data.
