2.3 Producing Robust Programs Flashcards

To get a 9 (45 cards)

1
Q

What is input validation?

A

Checking data input by the user meets specific criteria or rules before processing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Defensive design considerations: Type check

A

The input is in the correct data type (e.g. integer, real, string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Defensive design considerations: Range check

A

The input is within a correct range (e.g. between 1 & 2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Defensive design considerations: Presence check

A

Some data has been entered (e.g. reject blank inputs)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Defensive design considerations: Format check

A

The input is in the correct format (e.g. dd/mm/yyyy)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Defensive design considerations: Length check

A

The input has the correct (min/max) number of characters (e.g. passwords)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What can a programmer make their program by using input validation techniques?

A

By using input validation techniques, a programmer can make their program:

1) More robust

2) More user friendly

3) Prevent further errors occurring later in the algorithm

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does input validation help prevent?

A

The easiest way for a user to accidentally or intentionally misuse a program is when entering data. This can be prevented using input validation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Anticipating misuse: Division by zero

A

A programmer should always check that a variable isn’t zero before attempting a division by it to reduce the risk of their program crashing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Anticipating misuse: Communication error

A

Online systems require connections to host servers.
If this connection is dropped, unable to be established, or the system is overloaded, it could potentially cause a program to crash or hang when loading/saving data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Anticipating misuse: Communication error (solution)

A

A programmer should enable ways for the user to cancel requests or for them to fail gracefully, reporting the connection error.
The program may be able to automatically resume when the connection is available again.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Anticipating misuse: Printer and other peripheral errors

A

If a program outputs a hardcopy, the printer may run out of paper, ink, or have a jam.
The programmer should not assume that an output to a printer was successful and always have options to reprint reports or receipts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Anticipating misuse: What are disk errors?

A

Programs that read and write to files used to handle many types of exceptions, including:

1) The file/folder not being found

2) The disk being out of space

3) The data in the file being corrupt

4) The end of the file being reached

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Anticipating misuse: How are disk errors solved?

A

Robust programs will handle all these situations by checking files and data before attempting to use them for further processing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are common ways to increase the security of a password-based authentication system?

A

1) Force users to use strong passwords and change them regularly

2) Limit the number of failed authentication attempts before access to an account is lost

3) Ask for a random selection of characters from the password on each authentication

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is authentication?

A

Authentication can confirm the identity of a user before they’re allowed to access certain pieces of data or features of the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Data used by systems should be secure. How can this be achieved? (authentication)

A

1) Username and password to access systems

2) Recovering a password requires clicking on a link within the email that is sent to the registered address

3) Encryption of data files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Online bots can submit data automatically to online forms. How can this be protected against?

A

This can be protected against using software such as reCAPTCHA that verifies the user is human.

Programmers should also be aware of the potential for SQL hacks and other methods used by hackers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does a well-maintained program do?

A

A well-maintained program makes it easy for other programmers to understand what the code does.

They should be able to change parts of the source code without the risk of causing problems elsewhere in the code (e.g. knock on effects)

20
Q

Maintainability: comments

A

Use comments to explain the purpose of the program, explain sections of code (typically selections, iterations and procedures), explain unusual approaches that were necessary, visually divide sections of a program

21
Q

Maintainability: white space

A

Use white space to make sections of a program easier to see

22
Q

Maintainability: indentation

A

Use indentation for every selection and iteration branch (allows programmers to see the flaw of a program more clearly and pick out the different features)

23
Q

Maintainability: descriptive variable names

A

Use descriptive variable names, sub programs and parameters and explain their purpose with a comment when declared.

This helps programmers understand what they do and make it easier to keep track of them (e.g. names refer to what they actually are)

24
Q

Maintainability: procedures and/or functions

A

Use procedures and/or functions to structure the code and eliminate duplicating code (sub programs make it easier to see how different parts of a program work, which help them understand the overall program faster)

25
Maintainability: constants
Use constants declared at the top of a program
26
What are syntax errors?
Errors which break the grammatical rules of the programming language and stop it from being run/translated
27
Why do syntax errors happen?
1) Variables aren't declared or initialised before use 2) Incompatibility of variable types (e.g. total = "A" (total declared as an integer)) 3) Using assignments incorrectly 4) Keywords misspelt (e.g. prnt("Enter choice: "))
28
What are logic errors?
Errors which produce unexpected output but allow the program to keep running
29
Why do logic errors happen?
1) Conditions and arithmetic operations are wrong 2) Sequence of commands is wrong 3) Division by zero 4) Exceptions (e.g. file not found)
30
What are reasons for testing?
1) To ensure there are no errors (bugs) in the code 2) To check that the program has an acceptable performance and usability 3) To ensure that unauthorised access is prevented 4) To check the program meets the requirements
31
What is iterative testing?
1) Each new module is tested as it is written 2) Program branches are checked for functionality 3) Checking new modules do not introduce new errors in existing code 4) Tests to ensure that the program handles erroneous data and exceptional situations
32
Iterative testing is when program is tested...
The program is tested while it is being developed. Often a programmer will test a module, fix any errors they find, and then test it again. This process is repeated until the module is working correctly.
33
What is final/terminal testing?
1) Testing that all modules work together (integration testing) 2) Testing the program produces the required results with normal, boundary, invalid, and erroneous data 3) Checking the program meets the requirements with real data 4) A beta test may find more errors
34
Terminal testing is when program is tested....
The program is tested at the end of the development process. The whole program is tested at the same time to check that it's working correctly
35
How do we prevent errors and bugs?
1) Iterative testing is used to identify and fix small errors, which help prevent larger errors from occurring later on in the development process 2) Final testing is important as modules may work perfectly on their own but errors may occur when the modules interact with each other in the program 3) Using a combination of iterative and final testing is a good way to minimise the total number of bugs or errors that a program has when it is released
36
Suitable test data: normal inputs
Data which should be accepted by a program without causing errors
37
Suitable test data: boundary inputs
Data of the correct type which is on the edge of accepted validation boundaries
38
Suitable test data: invalid inputs
Data of the correct type but outside accepted validation checks so should be rejected by a computer system
39
Suitable test data: erroneous inputs
Data of the incorrect type which should be rejected by a computer system. This includes no input being given when one is expected.
40
What is refining algorithms to make them more robust about:
1) Writing code which anticipates a range of possible inputs 2) Those inputs could be invalid data or erroneous data 3) Making sure "bad" data doesn't crash the program 4) Making sure prompts to the user are descriptive and helpful (e.g. prompt to enter a code, code accepted, code is too short/long/contains non-numeric data) 5) Making sure only data of the correct "data type" are entered 6) Checking and handling missing or blank data
41
What is one option of refining algorithms?
One option is to use simple exception handling commands (available in most programming languages)
42
What should a good test plan have or be?
A test plan should be made before implementation, outline exactly what you're going to test and how you're going to test it. It should cover all possible paths in a program. A good test plan will anticipate all the potential issues with the program and select appropriate test data to test for these issues
43
What programmers try to do through defensive design?
Programmers try to protect their programs through defensive design. They will try to: 1) Anticipate and prevent users from misusing their programs 2) Ensure their code is well-maintained 3) Reduce the number of errors in the code through texting
44
What do structure diagrams and sub programs do?
Structure diagrams show the smaller tasks of a larger program. Simple sub programs can be written to carry out each individual task and the main program can be written from these
45
What are the advantages of structure diagrams?
1) Coding is easier as you're writing code for simple tasks 2) Lots of programmers can work at once as each module is written independently 3) Easier to test as all modules are tested individually 4) Individual sub programs can be fixed/updated without affecting the rest of the program 5) Can reuse sub programs in future programs