Code that survives bad input, and tests that find bugs on purpose. You can write the Python on the programming page; this unit is the discipline.
2.3.1 Defensive design
Assume the user, the network, and you-last-Tuesday will try to break it.
Anticipate misuse
Empty strings, letters in a number field, huge numbers, SQL-ish quotes, dividing by zero, file missing. Write the nasty cases down first.
Authentication
Prove the user is who they claim: username + password, better with 2FA. Store hashes, not plaintext passwords (the idea is enough at GCSE: you do not keep the real password sitting in a file).
Input validation
Check before you trust the value:
| Check | Meaning | Example |
|---|---|---|
| Presence | Not empty | Name required |
| Range | Between min and max | Age 0–120 |
| Type | Integer vs string | Age is digits |
| Format | Pattern | Postcode, email shape |
| Length | Min/max characters | Password ≥ 8 |
Validation is not verification. Validation = “does this look legal?” Verification = “is this the right data?” (type it twice; check a checksum).
Maintainable code
The next human (you in six months) must read it:
- Sensible names (
total_scorenotx1) - Indentation that matches nesting
- Comments that say why, not “this is a loop”
- Subprograms so each function does one job
Markers do award “maintainable” in long programming questions. Show it.
2.3.2 Testing
When
- Iterative testing — as you build, each bit
- Final / terminal testing — the whole thing against the original requirements
Error types (again, because Paper 2 loves them)
- Syntax — will not translate
- Logic — runs, wrong
- Runtime — crashes mid-flight
Test data
A test plan that only uses “happy” numbers will miss bugs.
| Kind | Meaning | Age 0–120 example |
|---|---|---|
| Normal (typical) | Valid, ordinary | 14 |
| Boundary (extreme valid) | On the edge of allowed | 0 and 120 |
| Invalid (erroneous) | Should be rejected | -1, 121, "hello" |
Some mark schemes also want extreme as a synonym for boundary. If they list three, use normal / boundary / invalid.
Write a table: test number, data, expected result, actual result, pass/fail. Even if “actual” is blank until you run it — the expected column is the thinking.
Exercises include writing a tiny validation routine and a test plan. Reveal when you want; skip if you already do this in your games.