Structured Coding



When structured programming techniques are used to create a program, certain rules are followed during coding. Four major rules govern the use of branching statements, the size of program modules, the definition of a proper program, and thorough documentation.

As previously discussed, one characteristic of structured programming is the lack of branching (GOTO) statements. The programmer writes the program within the confines of three logic patterns: the simple sequence, selection, and the loop. This discipline limits the use of the branch to jump from one program statement to another in a random fashion.

When branching statements are avoided, the programmer can code each module as an independent segment. Each module should be relatively small (generally no more than 50 or 60 lines) to facilitate the translation of modules into program statements. When module size is limited in this manner, the coding for each module fits on a single page of computer printout paper, which simplifies program testing and debugging.

Yet another rule of structured coding dictates that modules should have only one entrance point and one exit point. A program segment that has only one entrance point and one exit point is called a proper program (see Figure below). Following
this rule makes the basic logic flow easy to follow and simplifies the modification of a program at a later date.

Illustration of a Proper Program

A final rule to follow in writing structured programs is to include documentation, or comment statements, liberally throughout the program. The comments should explain the data items being used in the main module and document each of the lower-level modules. Documentation aids in testing and debugging programs, which should occur at intervals throughout the coding phase. Documentation is also helpful when the program needs to be modified at a later date. See Concept Summary below for a review of structured programming techniques.

 


Last Updated Jan.8/99