2.2.1 Programming Techniques Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Programming constructs

A
  • a programming construct determine the order in which lines of code are executed
  • 3 main programming constructs
  • selection
  • iteration
  • sequencing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Sequence

A
  • code is executed line by line in sequence from top to bottom
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Iteration

A
  • repeating a line or block of code using a loop
  • can either be count controlled or condition controlled
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Count controlled

A
  • (for loop)
  • is used when the number of iterations is known before execution and the block of code is executed a certain number of times
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Condition controlled

A
  • used when the number of iterations is not known so the block of code is only executed while a condition is met
  • while loop, do until loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Branching

A
  • the particular block of code is run if a specific condition is met
  • eg. If else statements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Recursion

A
  • is when a subroutine/function calls itself from within its own subroutine/function [1]
  • the function continues to call itself until a base case/stopping condition is met [1]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Importance of base case

A
  • without a base case, a recursive function may call itself indefinitely resulting in a stack overflow
  • the base case should be reachable within a finite number of times
  • for input values other than the stopping condition, the function must call itself
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Recursion benefits

A
  • quicker to write/ requires less lines of code [1] as some functions are naturally recursive
  • can reduce the size of a problem with each call [1]
  • recursion is suited to certain problems e.g problems involving trees or factorials [1]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Recursion drawbacks

A
  • more difficult to trace as each frame on the stack has its own set of variables [1]
  • requires more memory compared to the equivalent iterative algorithm in order to maintain the stack of calls [1]
  • risk of stack overflow if memory runs out e.g due to too many calls [1]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Scope

A
  • the section of code in which a variable can be accessed
  • a local variable within a subroutine takes precedence over a global variable with the same name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Local variables

A
  • can only be accessed with the subroutine in which they were defined [1]
  • multiple local variables with the same name can exist in different subroutines [1]/ same variable name be used in other modules without causing errors/overwriting
  • are deleted once the subroutine ends [1]
  • can overwrite global variables with the same name [1]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Global variables

A
  • can be accessed across the whole program [1] (so no need to pass as a parameter or redeclare
  • is used when a value needs to be accessible from various parts of a program [1]
  • value remains the same irrespective of where it is accessed [1]
  • e.g values of constants like pi or VAT rate [1]
  • not deleted until the program terminates so requires more memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Global variables drawbacks

A
  • make it difficult to integrate modules [1]
  • increase the complexity of a program [1]
  • they may cause conflicts with names in other modules [1]
  • may be modified unintentionally when the program is complex [1]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Modular programming

A
  • programs are split into separate self contained modules [1]
  • which can be written/tested individually [1]
  • modules can be subdivided further into smaller modules [1]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Modular programming advantages

A
  • modules can be reused in the current project and future projects which saves time [1]
  • modules can be shared between programmers so work is easier to divide between a team [1]
  • this reduces development time as work takes place in parallel [1]
  • modules can be allocated according to the programmers/team members expertise [1]
  • modules are easier to maintain/test/debug as each subroutine can be tested independently before integration [1]
17
Q

Function

A
  • a named block of code that performs a specific task and must always return a single value [1]
18
Q

Procedure

A
  • a named block of code that performs a specific task but does not have to return a value [1]
19
Q

Parameter

A
  • an item of data that is passed into a subroutine and can be discarded at the end of the subroutine [1]
20
Q

Parameter passing

A
  • by value
  • by reference
21
Q

Passing by Value

A
  • a local copy of the value/data is passed into the subroutine and discarded at the end of the subroutine [1]
  • so only the copy is changed [1]
  • this means value of the original data is unchanged/remains unaffected [1]
22
Q

Passing by Reference

A
  • the address/memory location of the data is sent [1]
  • so changes are made to the original data/changes the value in the variable passed [1]
  • changes remain even after the subroutine exits [1]
23
Q

IDE ( integrated development environment)

A

a program used for developing programs which provides a set of tools to make it easier for programmers to write, develop and debug code [1]

24
Q

IDE features

A
  • Stepping
  • break points
  • error diagnostics
  • variable watch window
  • syntax highlighting
  • autocomplete
25
Q

Stepping

A
  • runs the program line by line to check variable values at each stage
  • this allows programmers to watch the effects of each line of code [1]
26
Q

Breakpoints

A

Stop the program running at a set point to check the value of variables [1]

27
Q

Error diagnostics

A

To locate and fix errors

28
Q

Variable watch window

A
  • to watch how variables change as the program executes [1]
29
Q

Syntax highlighting

A
  • to identify keywords,variables and help identify syntax errors [1]
30
Q

Autocomplete

A
  • start typing a command/identifier and it completes it, this avoids spelling mistakes and saves time [1]