2.3 Producing robust programs Flashcards
(6 cards)
1
Q
What are the two types of defensive design considerations?
A
Anticipating misuse
Authentication
2
Q
What is input validation?
A
Checking data input by the user meets specific criteria/rules before processing.
3
Q
What are the 6 types of input validation?
A
- Type check: The input is in the correct data type eg. integer, real, string
- range check: the input is in the correct range eg. between 1 and 2 (inclusive)
- Presence check: some data has been entered eg. reject blank inputs
- format check: the data is in the correct format eg. dd/mm/yyyy
- Length check: the data has the correct (or min/max) number of characters eg. password, or telephone
- Lookup table: a table of acceptable entries, also called a list
4
Q
By using input validation techniques, what can a programmer ensure?
A
That their program is:
- more robust
- more user friendly
- prevent further errors occurring later in the algorithm
5
Q
What is anticipating misuse and what are the 4 different ways of anticipating misuse?
A
Anticipating misuse is planning ahead to take steps against potential misuse (eg. the app twitter/X prevents the same tweet sent twice in a row as it might be a spam).
- Division by zero
In mathematics, there is no number that when multiplied by 0 returns a non-0 number. Therefore the ALU cannot compute a division by 0. A programmer should always check that a variable is not 0 before attempting a division. - Communication error
Online systems require connections to host servers. If this connection is dropped, unable to be established or the server is overloaded, it could potentially cause a program to crash or hang when loading/saving data. A programmer should enable ways for the user to cancel requests or fail gracefully, reporting the connection error. The program may be able to automatically resume when the connection is available again. - Printer and other peripheral errors
If a program outputs a hardcopy, the printer may run out of ink, paper, or have a jam. The program should not assume that an output to a printer was successful and always have options to reprint reports or receipts. - Disk errors
Programs that read and write to files need to handle many types of exceptions, incl. file/folder not being found, disk out of space, data in file being corrupt, end of file reached. Robust programs will handle all these situations by checking files and data before attempting to use them for further processing.
6
Q
A