Paper 2 · Topic 2.3
2.3 Producing robust programs
Defensive design, testing and maintainable code. Taught in 6 lessons, each with its own 360° room, alongside the unit's PowerPoints, worksheets and lesson plans, and assessed on paper at the end.

What this topic covers
6 lessons, in teaching order.
Each lesson opens with retrieval from earlier lessons, is taught from its PowerPoint, and is explored in its room, where every station has a short explainer and questions. The topic follows the OCR J277 specification, section 2.3.
Lesson 1: Security desk
How can a programmer make sure a program copes with anything a user types?
Pupils learn to
- know what is meant by defensive design when writing programs
- understand why input validation is necessary
- know a range of validation techniques used to write robust programs
In the room Defensive design · Type check · Range check · Presence check · Format and length checks · Whitelists and blacklists · Final challenge: date checks
Lesson 2: Cyber defence HQ
How can a program defend itself against careless users and deliberate attackers?
Pupils learn to
- know what is meant by defensive design considerations
- know a range of problems that can occur when a program is running
- understand some authentication techniques programmers use
In the room Anticipating misuse · When things go wrong · Authentication · Forgotten passwords and new users · Bots and CAPTCHA · Validate a password · Final challenge: defend the program
Lesson 3: Code clinic
What does code maintainability mean?
Pupils learn to
- know why creating code that is easy to read is important with large projects
- understand what programmers can do to make their code more readable
- understand how to refine algorithms to make them more robust
In the room Naming conventions · Commenting · Indentation and white space · Sub-programs · Why maintainability matters · Refining an algorithm · Final challenge: good practice or bad?
Lesson 4: Bug hunt lab
What are the different types of errors that can occur in a program?
Pupils learn to
- know four reasons why a program should be tested
- know what iterative testing is
- know what final/terminal testing is
- know what a syntax error is
In the room Why test a program? · Iterative testing · Final (terminal) testing · Syntax errors · Logic errors · Error detective · Final challenge: syntax or logic?
Lesson 5: Test lab
What makes a good testing strategy?
Pupils learn to
- understand that just because a program works doesn't mean it works for all inputs
- understand that test data should include normal, boundary, invalid and erroneous data
In the room Why test with different data? · Normal data · Boundary data · Invalid data · Erroneous data · Test a comment box · Final challenge: sort the test data
Lesson 6: Revision HQ 2.3
What makes a robust program?
Pupils learn to
- understand how robust programs are made
- know which lessons I'm secure on and which to revise
In the room Lesson 1: Input validation · Lesson 2: Defensive design · Lesson 3: Maintainability · Lesson 4: Testing · Lesson 5: Test data · Plan an 8-mark answer · Final challenge: key terms · Syntax errors · Logic errors
End-of-topic test
An assessment sat on paper, with a mark scheme for the teacher.
Key words
The words to use in an answer.
- Defensive design
- An approach to programming that plans for things going wrong, using validation, authentication, anticipating misuse and maintainable code so a program cannot easily be broken.
- Type check
- A validation check that data is the correct data type, such as a whole number rather than text, before it is processed.
- Range check
- A validation check that data lies between set limits, such as 1 to 14, so values outside the limits are rejected.
- Presence check
- A validation check that some data has been entered, so a required field such as a username cannot be left blank.
- Format check
- A validation check that data follows a set pattern, with the right kind of character in each place, such as DD/MM/YYYY for a date.
- Length check
- A validation check that data has an allowed number of characters, such as exactly 11 digits for a mobile phone number.
- Anticipating misuse
- Thinking ahead, while a program is being written, about how users might accidentally or deliberately use it wrongly, and planning how the program will respond.
- Authentication
- Checking that a user is who they claim to be before they are allowed into a system, usually with a username and password.
- CAPTCHA
- A short test that humans can pass easily but programs find hard, used on forms to stop bots from submitting them.
- Bot
- A program that uses a website or service automatically while pretending to be a person, for example to create fake accounts or guess passwords.
- Maintainability
- How easy a program is for other programmers to understand, debug and change safely, helped by good names, comments, indentation and sub-programs.
- Naming convention
- An agreed set of rules for writing names in a program, such as camelCase or snake_case, applied the same way throughout so code is easy to read.
- Comment
- A note written in the code for people to read, explaining what a part of the program does or why; the translator ignores it.
- Indentation
- Space at the start of a line of code that shows which lines belong inside a structure such as a loop, selection or sub-program.
- White space
- Spaces and blank lines added to code to separate its parts and sections, making it easier for people to read without changing what it does.
- Testing
- Running a program on purpose with chosen inputs and checking the results, to find errors and show it meets its requirements before release.
- Iterative testing
- Testing each part of a program as it is written during development, fixing it, then testing again, including retesting earlier parts after a change.
- Final testing
- Testing of the complete program at the end of development, also called terminal testing, to check all parts work together and every requirement is met before release.
- Test data
- Inputs chosen on purpose to test a program, covering normal, boundary, invalid and erroneous values so every kind of situation is tried.
- Normal
- Test data that is typical, valid input the program should accept and process correctly, taken from well inside the accepted range.
- Boundary
- Test data that is valid but on the very edge of the accepted range, such as 11 and 19 for an age from 11 to 19.
- Invalid
- Test data of the correct data type but outside the accepted range, such as 24 for an age from 11 to 19, which should be rejected.
- Erroneous
- Test data of the wrong data type, such as text where a number is expected, which the program should reject without crashing.
- Test plan
- A table written before testing starts that lists each test, the data to use, the type of test data and the expected result.
And 4 more in the topic glossary, at the back of the pupil workbook.
Common mistakes
Where pupils go wrong.
Ideas that cost marks in this topic, each with the idea that replaces it.
- Testing proves a program has no errors.Testing can find errors; it cannot show that none are left.
- Syntax errors and logic errors show up the same way.A syntax error stops the program being translated. A logic error lets it run but gives the wrong result.
- Validation checks that data is correct.Validation checks that data is sensible and in the allowed form or range. A valid value can still be the wrong one.
- Boundary test data is always invalid.Boundary data sits at the edge of the allowed range; a value exactly on the limit should be accepted.
Using it
In the lesson, at home and in intervention.
For teachers
- The unit's lesson PowerPoints, worksheets and lesson plans, and the end-of-topic assessment with its mark scheme, in the Teacher Portal.
- Set any lesson for a class with a due date, and see who has finished.
- Reports show each station as Secure, Revise or Focus from pupils' first attempts, so a small group can go straight back to the right one.
- Ask for a teacher key
For pupils
- Sign in with the card your teacher gives you and open any lesson in this topic.
- Write each key fact in your own words on the worksheet before you check it.
- In Quiz Mode, pick this topic: every lost mark names the station that teaches it.
- Pupil sign in
Next and previous