2.2.1 Programming techniques Flashcards
(19 cards)
1
Q
What is sequencing?
A
- Code is executed line-by-line top to bottom
2
Q
What is branching?
A
- Section of code is only run if specifc condition met
3
Q
What is iteration?
A
- Block of code executed more than once
- Count-controlled: certain number of times
- Condition-controlled: while condition is met
4
Q
What is recursion?
A
- Programming construct where sub-routine calls itself
- Continues until base case is met
5
Q
Advantages of recursion?
A
- Code can be represented in fewer lines
- Easier to express some functions recursively
6
Q
Disadvantages of recursion?
A
- Risk of stack overflow if memory runs out
- Difficult to trace
7
Q
Variable facts
A
- Defined with either global or local scope
- Scope is section of code which variable can be accessed
- Local variable with same name is subroutine overwrite global variable
8
Q
What is a local variable?
A
- Defined within subroutine
- Can only be accessed within subroutine
- Are deleted when subroutine ends
- Ensures subroutines are self contained
9
Q
What is a global variable?
A
- Can be accessed across entire program
- Useful for values which are accessed often
- Risk being unintentionally edited
- Not deleted therefore more memory
10
Q
What is modularity?
A
- Splitting large programs into smalled self-contained modules
- Easier to divide tasks between team
- Each component can be tested individually
11
Q
What are functions and procedures?
A
- Sections of code that perform specific task
- Procedures dont return value
- Functions return single value
12
Q
What is passing by value?
A
- Copy of value is passed to subroutine
- Creates local copy
- Value outside subroutine is unaffected
13
Q
What is passing by reference?
A
- Address of parameter passed into subroutine
- Value of parameter updated at given address
14
Q
What are IDEs?
A
- Program that provides set of tools to help programmers develop and debug code
15
Q
Features of IDEs?
A
- TREE: translators, run time env, error diagnostics, editing
- CASA: Colour coding, automatic indentation, stepping, autocomplete
16
Q
What is a class?
A
- Template used to create objects
- Contains attributes defining object state
- Contains methods defining object behaviour
17
Q
What is encapsulation?
A
- Attributes cannot be directly edited or accessed
18
Q
What is inheritence?
A
- Child class inherits methods and attributes of parent class
19
Q
What is polymorphism?
A
- Inherited methods produce different outputs to that of parent class