Planning ahead to take steps against potential misuse (e.g Twitter preventing the same tweet sent twice in a row)
Input Sanitisation
Cleaning up data that has been input, (e.g. removing special characters to prevent a SQL injection)
Validation
Checking whether input data follows criteria and should be accepted (e.g. length check on a password)
Verification
Checking whether data has been entered correctly (e.g. double entry)
Authentication
Ensuring only authorised users can gain access to a system (e.g. passwords)
Maintainable code
Allowing other programmers to understand the code (e.g. comments, indentation, meaningful variable names)
Range Check
Checks data is within a certain range
Type Check
Checks data is a certain data type
Format Check
Checks data is entered in a certain way
Presence check
Checks that data has actually been entered and not left blank
Lookup table
A table of acceptable entries, also known as a list
Length check
Checks the length of the input is within a certain amount
Modularisation
Using subprograms to reuse code and make them easier to test
Appropriate variable names
Using a naming convention to ensure the purpose of a variable is immediately understood
Indentation
Improves readability and clearly shows each 'block' of code
Comments
Enable a programmer to understand the purpose of each line of code, crucial when working in a team
Robust programs can handle unexpected inputs and data without crashing and without being tricked into malicious action.
Reliable programs will work as intended under many different conditions or situations.
Contingency planning
It is impossible to predict all possible cases of misuse, but there are ways to help reduce errors. For example:
Providing helpful prompt messages.
Providing error-recovery routes (e.g. an undo feature).
Preventing access from certain parts of the system.
Using exception handling.
An exception is a description of the error that arose.
A comment is a line of code that is completely ignored by the computer.
Purpose of testing
Ensure a program works correctly no matter what input has been entered by the user
Ensure user requirements have been met
Ensure errors have been removed
Ensure the program doesn't crash while running
Iterative Testing
1. Programmer develops a module
2. Tests it
3. Repeats until module works as expected
Final Testing
1. Takes place after development and before program is released to end user
2. Ensures whole program works as originally expected
Syntax Error
Mistake in the grammar or spelling of the program
Prevents the program from being compiled
translators needs the code to be syntactically correct
example of syntax errors
Incorrect Spelling: pront ("hello")
Incorrect punctuation: print ("hello"(
Logical Error
Mistake made by the programmer
Program still works but displays the wrong output
Logical Errors
-Incorrect calculation:
total = num1 - num2,
print (total)
-Incorrect variable printed:
age = 16
name = "Steve"
print ("Nice to meet you" , age)
Test Data
Used to test whether a program is functioning correctly
Covers a range of possible and incorrect inputs, each designed to prove a program works or to highlight any flaws
Types of Test Data
Normal data - Sensible data that the program should accept and be able to process
Boundary data - Data at the extreme boundary of any data ranges
Invalid (AKA Erroneous) data - Data that the program cannot process and should not accept
Debugging is the process of finding and correcting existing and potential errors (also called bugs) in software code. Bugs can cause software code to behave unexpectedly or crash.
Common causes of logic errors
Not correctly understanding what the program needed to do
Using the incorrect logical operator in a selection statement
Missing or incorrect positioning of brackets in mathematical calculations, which means that the incorrect result is returned
Loops that execute more or fewer times than intended
Common causes of syntax errors
Spelling or typing errors
Missing parentheses, ( ) or { }
Missing colons (:), or semicolons, (;), in statements in which they are required by the language
Missing or unexpected indentation in Python
Printing a value without declaring it
Common causes of runtime errors
Trying to access a list item that does not exist
A mathematical calculation that results in the program trying to divide by 0
Trying to perform numerical operations on strings
Linking to a file or resource that has been moved or no longer exists
Logical operators
Symbols used to represent circuits of transistors within a computer
Common logical operators
NOT
AND
OR
Truth table
A visual way of displaying all possible outcomes of a logical operator
Truth table
The input and output values must be a Boolean value - usually 0 or 1 but occasionally True or False
Order of precedence
NOT
AND
OR
AND gate
An AND logical operator will output 1 only if both inputs are also 1