Defensive Design Flashcards

1
Q

What should never happen if programs are functioning correctly?

A
  • never break

- never produce errors

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

How will programmers try protect their programs?

A

Through defensive design

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

What are some examples of defensive design?

A
  • anticipate how users may misuse their program and then attempt to prevent it from happening again.
  • ensure their code is well maintained
  • reduce the number of errors in the code through testing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s the easiest way for a user to accidentally or unintentionally misuse a program?

A

When entering data

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

What are two ways you can prevent someone from entering something you don’t want them too?

A

Input sanitisation and input validation

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

What is input sanitisation?

A

removing any unwanted characters before passing data through the program.

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

What is input validation?

A

Checking if data meet certain criteria before passing it into the program. e.g. checking if an email address contains an @ symbol and has a suitable ending like .com

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

What are types of input validation you can use?

A
  • range check
  • presence check
  • check digit
  • format check
  • look-up table
  • length check
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a check digit?

A

Checks numerical data has been entered accurately.

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

What is a format check?

A

Checks the data has a correct format.

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

What is a look-up table?

A

Checks the data against a table of acceptable values.

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

What is a length check?

A

Checks the data is the correct length.

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

What is a range check?

A

Checks the data is within a specified range.

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

What is a presence check?

A

Checks the data has even accurately entered.

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

What does the function formatName() do?

A

It goes through the character of a string and deletes the character if it’s “(“ or “)” and returns the amended string.

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

What does the method removeChar(x) do?

A

Returns a new string with the character in position x removed.

17
Q

What is authentication?

A
  • 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 is using passwords.
18
Q

How can you increase the security of a password based authentication system?

A
  • force users to use strong passwords 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.
19
Q

Why is having too much authentication an issue?

A

Can affect a program’s functionality and put people off using it.

20
Q

What are the benefits of a well-maintained program?

A
  • makes it easy for other programmers to understand what the code does.
  • also be able to change parts of the source code without risk of causing problems elsewhere win the code.
21
Q

What features can improve the maintainability of source code?

A
  • comments
  • indentation
  • variables and subprograms should be named
  • using global variables only when necessary
22
Q

Why are comments good to improve the maintainability of source code?

A

Useful to explain the key features of a program and well written and clear comments help other programmers understand your code.

23
Q

Why is indentation good to improve the maintainability of source code?

A
  • separate different statements

- allows other programmers to see the flow of the program clearly and pick out different features

24
Q

How does naming your variables and sub programs improve the maintainability of source code?

A
  • refers to what they actually are

- helps programmers keep track and recognise what the variables are throughout the program.

25
Q

How does only using global variables when necessary help improve the maintainability of a program?

A
  • they could affect the rest of your code
  • variables with a local scope only affects the sub programs they are declared in
  • other programmers know changing these variables will affect other parts of the program
26
Q

Why does using a good amount of useful comments help your program?

A

Easy to produce a summary of what the program actually does using auto-documentation.