OCR Computing A-Level Revision

Standard Programming Techniques

Stepwise Refinement (3.7.a)

Stepwise refinement is a form of structured programming. The problem is defined in simple terms. These terms are split into more precise "sub-tasks" until each task can be written as a single procedure or function. Each module which is created can be created and tested separately (for example, by a different member of a team of programmers), and libraries can be used as modules or parts of modules. The individual modules can be reused in later projects.

Functions perform a single task, and return a single value.
Procedures do not necessarily return a value.

Both functions and procedures use local variables.

Parameters & Variables (3.7.b)

Parameter - data supplied to a function which is used as a local variable.
Local Variable - defined and only accessible within one module of a program. Data is lost once execution of the module is completed. The same (local) variable names can be used in different modules.
Global Variable - defined at the start of the program and exists until the program finishes. Data can be shared between modules using global variables, but they are overridden by local variables with the same name.

The Stack (3.7.c)

When one function calls another function, the memory address to return to and the local variables are "pushed" to the stack. Once the other function has finished, the local variables and return address are "popped". This process is recursive - so multiple sets of return addresses and variables can exist on the stack.