10.3 Thinking Procedurally Flashcards
Procedural Decomposition
Breaking a problem into a number of sub-problems, so that each sub-problem accomplishes an identifiable task (sub-problems may be divided even more)
Structured programming
A method of writing a computer program which uses:
- Modularization for program structure and organisation (breaking the problem down into subroutines)
- Structured code for the individual modules - that is, code which uses the basic constructs of sequence, selection and iteration
- Recursion
What are hierarchy charts often used for?
To show overall program structure
Hierarchy chart
- Each logical process is broken down into smaller components until it cannot be broken down any further
- Execution takes place from left to right, always at the lowest level component
- Selection and iteration are not shown in a hierarchy chart
Modularisation further advantages
- Large programs are broken down into subtasks/subroutine that are easier to program and manage
- Each subroutine can be individually tested
- Modules can be re-used several time in a program
- Frequently used modules can be saved in a library and used by other programs
- Several programmers can simultaneously work on different modules, shortening development time
- Easier to find errors in small self contained modules
- Well-organised, modular program is easier to follow
- Easier to find which module needs to be changed
- Self-contained modules mean that the change should not affect the rest of the program
- New features can be added by adding new modules
Modularisation advantages
- Programs are more easily and quickly written
- Programs are more reliable and have fewer errors
- Programs take less time to test and debug
- Programs are easier to maintain
Good programming practice techniques
- Meaningful indentifiers
- Define and document the inputs, outputs and preconditions for each sub-procedure
- Add lots of meaningful comments within the program
- At the bottom level, each sub-procedure should perform a single task
- Keep each sub-procedure self-contained by passing parameters and using local variables
Identifying the components
Involves writing procedures or functions and passing parameters