Week 9 Programming Theory Flashcards

(10 cards)

1
Q

Explain the difference between a variable and a constant

A

Value of a variable can change at runtime, value of a constant cannot

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

Explain the advantages of using named constants instead of hard-coded values. [2]

A

When the programmer wants to change the value it only needs changing in the declaration;
Can’t be changed accidentally/by the program;
Easier to understand the program / purpose of the data item stored in the constant so easier to debug;

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

What is a subroutine?

A

A named out-of-line block of code that can be called by writing its name.

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

What is a local variable?

A

A variable declared inside a subroutine which exists only while the subroutine is executing, and is only accessible inside the subroutine it is declared in.

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

What is a global variable?

A

A variable declared outside of a subroutine which is accessible to all parts of the program.

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

Explain why it is considered good practice to use local variables [3]

A

• Local variables use less memory // memory allocated to local variables can be reused when subroutine not in use;
• Using local variables makes subroutine self-contained;
• Using local variables aids modularisation;
• Variable names can be reused (in other parts of the program);
• Code is easier to re-use in other programs;

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

State three advantages of using subroutines and explain how each advantage is achieved

A
  • Easier to test/debug as each subroutine can be tested separately;
  • Easier to understand the code if sensible identifiers are used for subroutine names;
  • Code can be easily reused as each subroutine is independent of rest of program;
  • Makes it easier to work as a team of programmers as each subroutine can be worked on independently;
  • Can be used as often as needed without having to write the code each time;
  • Makes program easier to maintain/update (in future) as fewer changes will need to be made to make an update;
  • Easier to understand the code as each subroutine can be considered in isolation;
  • Less likely to be errors in the code due to reuse of code;
  • Reduces/eliminates side effects (e.g. unexpected change to value in global variable) through use of local variables;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is procedural abstraction?

A

The result of abstracting away the actual values used in any particular computation is called a procedure.

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

What is functional abstraction?

A

Functional abstraction disregards the particular computation method used.

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

What is problem decomposition?

A

Breaking a problem into a number of sub-problems, so that each sub-problem accomplishes an identifiable task, which might itself be further subdivided

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