In the early days of programming (1960's), the approach to writing software was relatively primitive and ineffective. Much of the code was written with goto
statements that transferred program control to another line in the code. Tracing this type of code was an exercise in jumping from one spot to another, leaving behind a trail of lines similar to spaghetti. The term "spaghetti code" comes from trying to trace code linked together with goto
statements. The complexity this added to code led to the development of structured programming.
-
The research of Bohm and Jacopini has led to the rules of structured programming. Here are five tenets of structured programming.
- No
goto
statements are to be used in writing code.
- All programs can be written in terms of three control structures: sequence, selection, and iteration.
- Each control structure has one entrance point and one exit point. We will sometimes allow for multiple exit points from a control structure using the
break
statement.
- Control structures may be stacked (sequenced) one after the other.
- Control structures may be nested inside other control structures.
The control structures of Java encourage structured programming. Staying within the guidelines of structured programming has led to great productivity gains in the field of software engineering.