Producing Robust Programs Flashcards
What is Defensive Design?
Defensive Design helps to ensure programs function/run properly and continue to run no matter what actions a user takes. This means that programs should never break or produce errors.
What is Anticipating Misuse?
Anticipating Misuse is thinking ahead about how users might misuse the program. They will then design the program to prevent this happening.
What is Authentication?
Authentication can confirm the identity of a user before they are allowed to access particular data or programs.
What is Input Validation?
Input Validation is checking that the data meets certain criteria before passing it into the program.
e.g. Checking that an email address contains an @ symbol.
What are the various types of validation?
Range Check
Length Check
Presence Check
Format Check
Type Check
What is a Range Check?
The input must fall within a specified range. This is usually applied to numbers and dates, but can apply to characters.
For example, the number entered must be between 1 and 100.
What is a Length Check?
The input must not be too long or too short.
For example, a username will require at least one letter, but can’t have more than 20.
What is a Presence Check?
A data value must be entered.
For example, entering a quantity when placing an order.
What is a Format Check?
The data must be in the correct format.
For example, entering a date in the format DD/MM/YYYY.
What is a Type Check?
The data must be of a specified data type.
For example, an integer must be entered when specifying a quantity.
What is a disadvantage of Validation Checks?
Validation does not ensure that the data entered is correct, just that it is possible and sensible. A user may accidentally enter a date of birth that is possible and sensible, but incorrect. The program has no way of knowing that the date has been entered incorrectly.
To get around this, many programs include verification checks - they repeat the entered data to the user and ask them to confirm if this data is correct. If the user confirms the data, the program then assumes it to be correct. This is an example of how planning the design of a program can help reduce errors.
What is Maintainability?
A well-maintained program makes it easy for other programmers to understand your code. This can include using sub programs, comments, indents, clear naming
What things are included in making Maintainability?
Naming conventions
Indentation
Commenting
Use of sub-programs
What is Naming Conventions?
Choosing a variable name that reflects the purpose of the variable and the
data it is intended to hold, instead of variables like x,y,z.
(makes the program more understandable)
What is Indentation?
Code within selections or iterations should be indented. This allows the programmer to easily see which code falls within the selection or iteration, and where it ends.
(makes the program more understandable)
What is Commenting?
Comments are lines in programs that provide information about what the different parts of the program do. They serve no other purpose, and are not executed when the program is run - the program simply ignores them and moves on to the next line of code.
(makes the program more understandable)
What are Sub-programs?
Subprograms are small programs that are written within a larger, main program. The purpose of a subprogram is to perform a specific task. This task may need to be done more than once at various points in the main program.
What are the two types of Sub-programs?
Procedures
Functions
What is a Procedure?
Procedures carry out a set of instructions and do not return a value.
What is a Function?
A function is a similar to a procedure but it will return a value.
What is a Parameter?
Procedures or functions may be given variables to use.
These are called parameters.
Parameters are passed to a sub program.
What are benefits of using Sub-programs?
How do Sub-programs improve Maintainability?
The main benefit that is fact sub programs give a program structure.
This makes it easier to follow and understand.
A subprogram may be used repeatedly at various points in the main program. However, the code only has to be written once, resulting in shorter programs.
Subprograms are usually small in size, meaning they are much easier to write, test and
debug.
What are the two types of error that often occur when developing a program?
Syntax error
Logic error
What is a Syntax Error?
Error in a program resulting from code that has been entered not following syntax rules or grammar rules governing how to write statements in a programming language.
- misspelling a statement, eg writing pint instead of print
- using a variable before it has been declared
- missing brackets, eg opening a bracket but not closing it