What are the key factors of structured programming? | • Simple building blocks whose individual correctness can be easily proven
•Well-defined rules that enable correct assembly of these building blocks |
Structured programming - Rule of thumb | •No »free« jump statements (»Goto considerd harmful« – Edsger Dijkstra, 1968)
•Each loop has exactly one entry and exactly one exit point (➝ no break)
• Statements should have exactly one effect (no »side effects«)
• In multiway branches (switch) always exactly one path should be traversed (➝ no sequential continuation, always specify default clause) |
Structured programming - Rule of thumb (2) | • Subroutines communicate with each other exclusively via parameters and function values (or via class and instance variables – see later) and not via shared, global data structures
• A subroutine should also be documented as precisely as possible (ideally formally), in particular:
• the effect mentioned above (»postcondition of the subroutine«)
• the conditions that must be met for the subroutine to be able to achieve this effect (»precondition of the subroutine«) |