click below
click below
Normal Size Small Size show me how
techniques
2.2 - programming techniques
Term | Definition |
---|---|
sequence | when code runs in a specific (often linear) order |
iteration/looping | whenever code is set to run multiple times |
count vs condition controlled loops | count controlled loops iterate code a specific number of times condition controlled loops iterate code until a statement is true |
selection/branching | when the order of the code/ the code ran depends on a condition |
nest structures | whenever different techniques are combined in the same project (eg a for loop within an if statement) |
global variables | variables that are stored outside of a function i.e. they can be used anywhere within the program |
local variables | variables that can only be used within the function they are defined in, and their memory address is wiped whenever the function is finished |
global variable issues | can be used and therefore tampered with anywhere within the program their storage in memory can be inconsistent due to their function generally considered bad programming practice, but can be sometimes necessary |
modularity | the process of decomposing a problem down into smaller, more manageable chunks, giving each chunk with a sub-procedure |
procedures vs functions | both are subroutines, yet only functions return a value |
parameters | the values the sub procedure need when a function is called (used in their definition) |
passing by value | where a parameter that the subroutine uses is treated as a local variable based on the argument (variables passed in will not change as the sub-procedure changes it) |
passing by reference | where a parameter that the subroutine uses changes the value of the argument directly (variables passed in will change as the sub procedure changes it) |
IDEs | Integrated Development Environments - programs that help users code more effectively and effectively, often by either helping them directly or abstracting/managing the more complicated parts of programming |
IDE stereotypical benefits | - code highlighting/autocompletion/autocorrection - auto compiling - inbuilt debuggers (often telling the coder what exactly caused the error) - auto documentation/saving |
arguments | the values the sub procedure uses when a function is called (used when they're called) |
rules of recursion to prevent indefinite iterations | - contains a stopping condition (base case) - the base case should be reachable in a finite number of iterations - the function iterates itself if it's not using the base case |
ways of visualizing the order/events of code code | using a truth table (selection), flow chart (general case), stacks (often for iteration/recursion) |
recursion benefits / downsides | whilst it is powerful to use if the coder is aware of it, saving lines and preforming tasks that pure iteration can not do, it is not very efficient in memory as a new copy of the function is needed for every iteration of the recursion |
when should object oriented programming be used? | when you’re able to encapsulate and model entities as objects, defining them as classes and investigating how they should interact with each other |
main examples of OOP | GUI (graphics user interface) Computer games |
recursion | when a sub-procedure is defined in terms of itself (the sub-procedure calls itself somewhere within it) |