section 7 - design, testing, IDE's Flashcards
well-maintained programs
When using structured programming, it’s important that your code is well-maintained.
A well-maintained program makes it easy for other programmers to understand what the code does. They should also be able to change parts of the source code without the risk of causing problems elsewhere in the code (e.g. knock on effects).
features that improve the maintainability of source code - Comments
useful for explaining what the key features of a program do - well written and clear comments are fundamental for helping other programmers understand your programs.
features that improve the maintainability of source code - indentation
used to separate different statements in a program. This allows other programmers to see the flow of the program more clearly and pick out the different features.
features that improve the maintainability of source code - naming of Variables, sub programs and parameters
Variables, sub programs and parameters should be named so that they refer to what they actually are. This helps programmers to understand what they do, and makes it easier to keep track of them. It’s also important that they follow the standard naming conventions
features that improve the maintainability of source code - use of sub programs
Using sub programs can make it easier for other programmers to see how different parts of a program work, which can help them understand the overall program faster.
Defensive Design
When programs are functioning correctly they should never break or produce errors. In practice this is difficult to achieve.
Programmers try to protect their programs through defensive design. They will try to:
- Anticipate how users might misuse their program, then attempt to prevent it from happening.
- Ensure their code is well-maintained
- Reduce the number of errors in the code through testing
input validation
Checking if data meets certain criteria before passing it into the program.
E.g. checking that an email address contains an @ symbol and has a suitable ending (.com, .co.uk, etc).
This prevents users from accidentally or intentionally misusing a program when entering data.
Programs can use a mixture of input validation checks to verify that the inputted data has an acceptable format before passing it into the program.
types of input validation check you can use
Range check
Presence check
Format check
Look-up table
Length check
Range check
Checks the data is within a specified range
presence check
Checks the data has actually been entered.
format check
Checks the data has the correct format (e.g. a date).
look-up table
Checks the data against a table of acceptable values.
length check
Checks the data is the correct length.
authentication
Authentication can confirm the identity of a user before they’re allowed to access certain pieces of data or features of the program. A common way that programs do this is using passwords - It’s important that programmers get the level of authentication correct - too much authentication can affect a program’s functionality and put people off using it
authentication - passwords
Passwords are usually associated with a username. When someone tries to access a protected part of the program, it should ask them for their password to check that they are who they claim to be.
common ways to increase the security of a password-based authentication system
- Force users to use strong passwords (see p.46) and get them to change their passwords regularly.
- Limit the number of failed authentication attempts before access to an account is lost.
- Ask for a random selection of characters from the password on each authentication.
syntax errors
when the compiler or interpreter doesn’t understand something you’ve typed because it doesn’t follow the rules or grammar of the programming language.
Syntax errors can be diagnosed by compilers and interpreters - they’ll be unable to translate the source code and a syntax error (with its location) will be returned.
logic errors
when the compiler or interpreter is able to run the program, but the program does something unexpected.
Logic errors are more difficult to diagnose and track down - compilers and interpreters won’t pick them up. Logic errors are found through general use of the program and by systematically testing it using a test plan.
Programming Errors
It’s quite typical for a program to contain errors during its development these errors need to be found and corrected as soon as possible.
The first task is to figure out what type of error has occurred.
Once you have identified the errors in a program, you can then refine your code to fix them.