Defensive Design Flashcards
What should never happen if programs are functioning correctly?
- never break
- never produce errors
How will programmers try protect their programs?
Through defensive design
What are some examples of defensive design?
- anticipate how users may misuse their program and then attempt to prevent it from happening again.
- ensure their code is well maintained
- reduce the number of errors in the code through testing
What’s the easiest way for a user to accidentally or unintentionally misuse a program?
When entering data
What are two ways you can prevent someone from entering something you don’t want them too?
Input sanitisation and input validation
What is input sanitisation?
removing any unwanted characters before passing data through the program.
What is input validation?
Checking if data meet certain criteria before passing it into the program. e.g. checking if an email address contains an @ symbol and has a suitable ending like .com
What are types of input validation you can use?
- range check
- presence check
- check digit
- format check
- look-up table
- length check
What is a check digit?
Checks numerical data has been entered accurately.
What is a format check?
Checks the data has a correct format.
What is a look-up table?
Checks the data against a table of acceptable values.
What is a length check?
Checks the data is the correct length.
What is a range check?
Checks the data is within a specified range.
What is a presence check?
Checks the data has even accurately entered.
What does the function formatName() do?
It goes through the character of a string and deletes the character if it’s “(“ or “)” and returns the amended string.