2.2.1 Programming Techniques Flashcards
Name 3 programming constructs.
Sequence
Selection
Iteration
What is meant by sequence?
Code is executed line-by line from top to bottom
What is meant by selection?
Particular block of code is run if a specific condition is met
Which statements are examples of selection?
If
Else
Name the 2 types of iteration.
Count-controlled
Condition-controlled
What is meant by count-controlled iteration?
Block of code executed a certain number of times
What is meant by condition-controlled iteration?
Block of code executed while a condition is met
Which loops are examples of iteration?
For
While
What is recursion?
A programming construct in which a subroutine calls itself during its execution
How long does recursion continue?
Until a stopping condition is met
Give 2 advantages of recursion.
Can be represented in fewer lines of code
Easier to express some functions recursively
Give 2 disadvantages of recursion.
Risk of stack overflow if memory runs out
Difficult to trace
Which two ways can variables be defined?
Within a global scope
Within a local scope
What is meant by scope?
The section of code in which a variable can be accessed
Where can local variables be accessed?
Only within the subroutine in which they are defined
Where can global variables be accessed?
Across the whole program
What are 2 benefits of local variables?
Ensures subroutines are self-contained
Multiple local variables with the same name can exist in different subroutines
What are 2 disadvantages of global variables?
Requires more memory as not deleted until program terminates, local variables are deleted once the subroutine ends
Danger of being unintentionally edited
What is modular programming?
A technique used to split large, complex programs into smaller, self-contained modules
Give 3 benefits of using modular programming.
Improves reusability of components
Simplifies testing & maintenance
Easier project management
What is stepwise refinement / top-down design?
Technique used to modularise programs by breaking down problem into sub-problems until each is an individual, self-contained module performing a certain task
What is a function?
Named block of code that performs a specific task
Always returns a single value
What is a procedure?
Named block of code that performs a specific task
Do not have to return value
State the two methods by which parameters can be passed.
By reference
By value
What is meant by passing by value?
A copy of the value is passed to the subroutine and discarded at the end
Value external to subroutine remains the same
What is meant by passing by reference?
Address of parameter is given to subroutine
Value will be updated at given address
What does IDE stand for?
Integrated Development Environment
What is an IDE?
Program providing a set of tools that allow programmers to write, develop & debug code easily
State the 5 common features of IDEs.
Stepping
Variable watch
Breakpoint
Source code editor
Debugging tools
What is meant by stepping?
Executes a single line at a time
Allows programmer to monitor the effect of each individual line of code
What is meant by variable watch?
Used to observe how the contents of a variable change in real-time through the execution of a program
What is meant by breakpoint?
Allows programmer to set a point in the program for it to stop
Either based on a condition or at specific line
Helps pinpoint errors
What is meant by source code editor?
Aims to make coding process easier
Includes autocompletion of words, indentation, syntax highlighting & automatic bracket completion
What is meant by debugging tools?
Run-time detection of errors with a guide to where in the code they are likely to have occured through line numbers and highlighting
What is a class?
A template for an object
Defines the state & behaviour
How is the state of an object defined?
Attributes
Give an object’s properties
How is the behaviour of an object defined?
Methods
Describe actions an object can perform
What is instantiation?
An object is an instance of a class
A class can be used to create multiple objects with the same set of attributes & methods
What is encapsulation?
Attributes are declared as private so can only be altered by public methods
Why is encapsulation used?
Makes programs less complex by protecting data from being accidentally edited