- Design first: decomposition into modules
Break a big problem into small, named sub-tasks before writing any code.
Before writing a single line of code, a good programmer designs the solution. The key idea is decomposition: split a large, complex problem into smaller sub-tasks, each of which is easier to understand, solve and test on its own.
Each sub-task becomes a module — a self-contained block of code that does one clear job. In 9618 a module is implemented as either:
| Subroutine type | Returns a value? | How it is called |
|---|---|---|
| Procedure | No (performs an action) | CALL DoSomething(...) |
| Function | Yes (returns one value) | inside an expression, e.g. x ← Calculate(...) |
Why decompose?
- Each module can be written and tested separately.
- Modules can be reused in other parts of the program (or other programs).
- The program is easier to maintain — a change to one module rarely breaks the others.
- A team can work on different modules at the same time.
The two design tools in this topic both come from this idea: a structure chart records the modules of the solution, and a state-transition diagram records the behaviour of the system.
- Decomposition = split a problem into smaller sub-tasks.
- Each sub-task → a module (procedure or function).
- Procedure performs an action; function returns one value.
- Benefits: separate testing, reuse, easier maintenance, teamwork.