2.3 Producing Robust Programs Flashcards
What does input validation do?
Input Validation is checking data input by the user meets specific criteria / rules before processing.
Why do we use Input validation?
By using Input validation the program is more:
- Robust
- User Friendly
- Prevent Errors occurring later in the algorithm
What are the types of checks
Troubled
Lemons
Race
Funny
Pumpkins
- Type Check
- *Check whether data is the right type**
- Range Check
- *In data in the correct range. E.g. 1- 10**
- Presence Check
- *Is the data actually there. It rejects blank inputes**
- Format Check
- *Is the data in the right format. E.g. dd/mm/yy**
- Length Check
- *Is it the right length. E.g. Password is too short or too long**
What are some of the issues you have to anticipate?
- Dividing by Zero.
- Communication Error
- Printer or Peripheral Error
- Disk Error
Robust programs will handle all these situations by checking files and data before attempting to use them for further processing.
How is Dividing by 0 a problem?
In mathematics, there is no number which when multiplied by zero returns a non-zero number. Therefore the ALU cannot compute a division by zero.
How is Communication error a problem?
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.
How is Peripheral error a problem?
Any peripheral may be in an error mode (e.g. paper jam)
How is Disk error a problem?
Programs that read and write to files must handle exceptions, including:
- The file/folder not being found.
- The disk being out of space.
- The data in the file being corrupt.
- The end of the file being reached
What is Authentication?
What are the ways it can be achieved?
- Authentication is the process of a user confirming that they are who they say they are on a computer system.
This can be achieved with:
- Username and password to access systems
- Recovering a password requiring clicking on a link within the email that is sent to the registered address
- Encryption of data files
- Check for human and not bot attempting access (e.g. reCAPTCHA)
The factors of authentication can be broken down into three main groups:
something you are - username, bank account number, or anything that identifies the user uniquely
something you know - password, pin, secret answer to a question
something you have - swipe card, biometrics
- Programmers should also be aware of the potential for SQL injection hacks and other used by hackers.
How can you increase Maintainability of a program? wcidpc
Comments, white space, indentation, variable names, procedures and constants
- Use Comments to Explain the purpose of program & sections of code. Typically selections, iterations and procedures. They can also explain unusual approaches.
- Use white space to make sections of a program easier to read as it stands out more
- Use Indentation for selection and iteration allows the programmer to easily see which code falls within the selection or iteration, and where it ends.
- Use descriptive variable names and explain their purpose with a comment when declared.
- User procedures and/or function to Structure the code & Eliminate duplicating portions
- Use constants declared at the top of the program.
Why do we test our program?
- To ensure there are no errors(bugs) in the code.
- To check that the program has an acceptable performance and usability
- To ensure that the unauthorised access is prevented
- To check the program meets the requirements
What is iterative testing?
Performed whilst the software is being developed
- Each new module is tested as it is written.
- Program branches are checked for functionality.
-
Checking new modules do not introduce new errors I not existing
code. -
Tests to ensure the program handles erroneous data and
exceptional situations.
What is terminal testing?
Performed when the program is finished
- Testing that all modules work together (integration testing)
- Testing the program produces the require results with normal, boundary, invalid and erroneous data.
- Checking the program meetings the requirements with real data.
What are Syntax errors
- The rules of the language have been broken
- The program will not run (Compiled languages)
Syntax errors happen because:
- Variables are not declared or initialised before use
- Incompatibility of variables types e.g. total = “A”
- Using assignments incorrectly
- Keywords misspelt
What are logic errors and why do logic errors happen
The programs run but does not give expected output
Logic errors can happen because:
- Conditions and arithmetic operations are wrong
- Sequence of commands is wrong
- Division by zero
- Exceptions