GGCSE Revision Hub

3.2.11 Robust and secure programming

AQA Computer Science 8525Topic 3.2 — ProgrammingFoundation & Higher

This is the longest topic in the specification and the one that carries most of the Paper 1 marks. It covers the statements every program is built from, the operators that do the work, the structures that hold data, and the discipline that makes code safe to rely on. Two of the specification's supported languages are Python and C#, so the examples here use Python-style syntax with the AQA pseudo-code where the specification demands it. Learn this as something you write, not something you memorise.

What you need to know

What robustness means

A robust program keeps working when things go wrong. It does not crash, it does not give a nonsensical answer, and it tells the user what it wants when the input is not what it expected. The specification asks for validation routines, authentication routines, testing, test data and error identification, and all of them are about that.

Key fact: A robust program handles bad input and unexpected situations without crashing or producing nonsense.

Data validation

Be able to write simple data validation routines that check the validity of data being entered by a user. The examples given are: checking if an entered string has a minimum length, checking if a string is empty, and checking if data entered lies within a given range, for example between 1 and 10. Each of these is a condition that must be true before the program carries on.

Key fact: Validation checks: minimum length, not empty, and within a range.

Authentication

Be able to write a simple authentication routine that uses a username and password. Students will only be required to use plain text usernames and passwords, so you do not need to encrypt them. What the routine does is compare what was typed with what is stored, and accept or reject. The point is that the check happens in the program rather than being assumed.

Key fact: An authentication routine compares a typed username and password with the stored ones and accepts or rejects.

Testing and test data

Understand what is meant by testing in the context of algorithms and programs, and be able to correct errors within algorithms and programs. Understand what test data is and describe the following types: normal (typical) data, boundary (extreme) data and erroneous data. Normal data is a sensible value the program should handle; boundary data is the value right at the edge of what is allowed; erroneous data is a value the program should refuse.

Key fact: Three types of test data: normal (typical), boundary (extreme) and erroneous.

Boundary data in detail

Boundary data would be, for example, 0, 1, 10 and 11 if the allowed range is 1 to 10 — that is, either side of the allowed boundary. These are the cases that catch off-by-one errors, because a program that uses > instead of >= will pass every normal test and still fail at the boundary.

Key fact: For an allowed range of 1 to 10 the boundary data is 0, 1, 10 and 11.

Choosing and justifying test data

Be able to select and justify the choice of suitable test data for a given problem. Justification is what earns the marks: explain that 0 and 11 are boundary data because they are just outside the allowed range, that -5 is erroneous data because it could never be valid, and that 7 is normal data because it is an ordinary value inside the range.

Key fact: Justifying test data means saying why each value is normal, boundary or erroneous.

Two kinds of error

Understand that there are different types of error: syntax error and logic error. A syntax error is when the program cannot be run at all because the code does not follow the rules of the language. A logic error is when the program runs perfectly happily but does the wrong thing — a mistyped condition, a wrong variable, an off-by-one. Syntax errors are found by the interpreter; logic errors are found by testing.

Key fact: A syntax error stops the program running; a logic error lets it run but do the wrong thing.

Flashcards

Exam questions

Written in the style of AQA Computer Science, with a mark scheme for each one. No question here is a real past paper question.

mcq1 mark

A program accepts a mark between 1 and 10. Which set of test data is boundary data?

  • 0, 1, 10, 11
  • 5, 7, 9
  • -100, 0, 100
  • 1, 5, 10

Mark scheme: 1 mark for choosing 0, 1, 10 and 11, which are either side of the allowed boundary of 1 to 10. The first and last options are normal data and the third contains values that are simply invalid.

short3 marks

Explain in English the difference between a syntax error and a logic error, and how each is found.

Mark scheme: 1 mark for stating that a syntax error means the code does not follow the rules of the language so the program cannot run. 1 mark for stating that a logic error means the program runs but does the wrong thing. 1 mark for explaining that syntax errors are reported by the interpreter while logic errors are only found by testing with suitable test data.

six6 marks

Explain in English how a programmer makes a program robust, and what test data is used for.

Mark scheme: Level 1 (1-2 marks): A short answer saying validation, testing and error handling make a program robust. Level 2 (3-4 marks): A structured answer covering validation checks, the three types of test data and the two types of error. Level 3 (5-6 marks): A detailed answer explaining validation routines for minimum length, empty strings and ranges, and why they stop a program crashing or misbehaving, describing normal, boundary and erroneous data with the 1 to 10 example, explaining that boundary data catches off-by-one errors that normal data would miss, explaining the need to justify the choice of test data, and distinguishing a syntax error, which prevents the program running, from a logic error, which only testing can reveal.

Other sections in this topic

Practise these questions

Answer them in the interactive view and they get marked against the same mark scheme, one mark at a time, with the reason for each mark.

Open the interactive topic →