Producing robust programs Flashcards
Producing robust programs
What is Defensive Design?
Means that all possible contingencies are planned for including accidental or deliberate incorrect inputs or menu option selection
Producing robust programs
What is this?
Means that all possible contingencies are planned for including accidental or deliberate incorrect inputs or menu option selection
Defensive Design
It ensures that
Errors / bugs are kept to a minimum
Programs behave as expected even if the user does something unexpected
All possible errors that could occur are identified and catered for
Producing robust programs
What does Defensive Design try to ensure?
Errors / bugs are kept to a minimum
Programs behave as expected even if the user does something unexpected
All possible errors that could occur are identified and catered for
Producing robust programs
Defensive Design
What is Input Sanitisation?
- Removing ‘white space’ from user input
* Converting user input so that it is all one case, e.g. upper case
Producing robust programs
Defensive Design
What does this describe?
• Removing ‘white space’ from user input
• Converting user input so that it is all one case, e.g. upper case
Input Sanitisation
Producing robust programs
Defensive Design
What is Validation?
- Range checks – checks input is between minimum and maximum values
- Data type checks – checks data, for example, is numeric / alphabetic
- Length check – checks data is a certain number of characters long
- Presence check – checks field is not empty, e.g. must enter a name
Producing robust programs
Defensive Design
What is :
- Range checks – checks input is between minimum and maximum values
- Data type checks – checks data, for example, is numeric / alphabetic
- Length check – checks data is a certain number of characters long
- Presence check – checks field is not empty, e.g. must enter a name
Validation
Producing robust programs
Defensive Design
What is Authentication?
- Authentication is the process of checking the identity of a user
- This is done using user names and passwords. Passwords will be stored in encrypted form
- Authentication checks that the username and password entered exist
- Using software such as reCaptcha to check that the user is human and not an online bot, automatically entering data in online forms
Producing robust programs
Defensive Design
What is this?
- Authentication is the process of checking the identity of a user
- This is done using user names and passwords. Passwords will be stored in encrypted form
- Authentication checks that the username and password entered exist
- Using software such as reCaptcha to check that the user is human and not an online bot, automatically entering data in online forms
Authentication
Producing robust programs
Defensive Design
How should you plan for contingencies? (4 things)
- Programs should check for potential errors such as division by 0
- Programs should give users options to Cancel requests / provide error messages
- Programs should not assume that a request to print has been successful so should always provide an option to reprint
- Programs accessing files should not assume that the file will be found or that a file has anything in it
Producing robust programs
Defensive Design
What is this called?
- Programs should check for potential errors such as division by 0
- Programs should give users options to Cancel requests / provide error messages
- Programs should not assume that a request to print has been successful so should always provide an option to reprint
- Programs accessing files should not assume that the file will be found or that a file has anything in it
planning for contingencies
Producing robust programs
Maintainability
Why do programmes need to be easy to maintain?
So if you return to code to, for example, add more features, you can understand what you did
So people who you are working with can pick up your code and easily work with and understand what you have done
Producing robust programs
What are these?
So if you return to code to, for example, add more features, you can understand what you did
So people who you are working with can pick up your code and easily work with and understand what you have done
reasons why programmes need to be easy to maintain
Producing robust programs
Maintainability
How can programmers ensure the code they write is easy to maintain?
Use comments to:
• Explain the purpose of the program
• Explain sections of code
• Explain unusual approaches
• Visually divide sections of a program
Use whitespace to make sections of a program easier to see
Use indentations for every selection and iteration branch
Use descriptive variable names and explain their purpose with a comment
Use procedures and functions to:
• Structure the code
• Eliminate duplicate code
Use constants declared at the top of a program
Producing robust programs
Maintainability
What are these?
Use comments to:
• Explain the purpose of the program
• Explain sections of code
• Explain unusual approaches
• Visually divide sections of a program
Use whitespace to make sections of a program easier to see
Use indentations for every selection and iteration branch
Use descriptive variable names and explain their purpose with a comment
Use procedures and functions to:
• Structure the code
• Eliminate duplicate code
Use constants declared at the top of a program
ways programmers can ensure the code they write is easy to maintain