a programming technique that emphasizes clear logic, modularity, and avoidance of GO TO statements (which are intrinsically error-prone).
One of the most important barriers to the development of better computer software is the limited ability of human beings to understand the programs that they write. Structured programming is a style of programming designed to make programs more comprehensible and programming errors less frequent. Because it is more a popular movement than a precise theory, structured programming can be defined in several ways, but it usually includes the following;
- Block structure. The statements in the program must be organized into functional groups. For example, of the following two Pascal program fragments, the first is structured, while the second is not:
Note that it is much easier to tell what the first example does. - Avoidance of jumps ("GO-TO-less programming"). It can be proved mathematically that, if a language has structures equivalent to the (block-structured) IF-THEN and WHILE statements in Pascal, it does not need a GO TO statement. Moreover, GO TO statements are often involved in programming errors; the programmer becomes confused as to the exact conditions under which a particular group of statements will execute.
Advocates of structured programming allow GO TO statements only under very restricted circumstances (e.g., to deal with error conditions that completely break out of the logic of a program) or not at all.
- Modularity. lf a sequence of statements continues uninterrupted for more than about 50 lines, human beings have a hard time understanding it because there is too much information for them to keep track of. As an alternative, programs should be broken up into subroutines, even if some of the subroutines are called only once. Then the main program will read like an outline, and the programmer will never need to understand more than about one page of code at a time. (The programmer must know what the subroutines do, but not how they do it.) This principle is sometimes called information hiding-irrelevant information should be kept out of the programmer's way. Structured programming was first advocated by E.W. Dijkstra in the early 1970s.
