|
3.2
PRINCIPLES OF STRUCTURED PROGRAMMING
Structured
programming is a method of designing computer programs to minimize
complexity (Kittner and Northcutt,
1984). Principles of structured programming are delineated in
this section. Generally speaking, personal computer programs presented
in this book have been developed with these principles in mind.
Of course, these rules cannot always be followed rigidly, especially
when efficiency or speed of computation is the major consideration.
1. The
program should be "egoless", that is, easy to read and understand.
Due to high manpower cost, clarity and simplicity should be valued
more than complicated efficiency.
- Choose
variable names close to standard and customary notations.
- Insert
spaces within the program statements for better readability.
- Use
comment statements generously throughout the program for internal
documentation.
- Use
blank statements to skip lines between blocks of the program.
- Indent
statements within a loop.
- Define
the variables within the program.
- Use
one statement per line.
2. The
program should be easy to modify and maintain.
- Use
variables for constant values that may change in the future. Place
the constant values at the beginning of the program.
- Initialize
all the variables at the beginning of the program.
3. The
program should be designed to maximize programmer efficiency (Kittner
and Northcutt, 1984).
- Use
top-down programming; that is, design he program in stages from
simple to complex.
- Use
a flow chart in designing the logic of the program.
- Avoid
GOTO statements as much as possible in procedural languages such
as FORTRAN and BASIC. This will prevent unnecessary complexity
(the so-called "spaghetti" effect) and make the program logic
easier to follow.
- Use
modular programming. This approach will help to use fewer GOTO
statements.
- The
relationship between modules (coupling) should be weak. Each module
should be as independent of the others as possible.
- A
module should preferably have a single entry and single exit.
- A
module should not be big in size. A good size is a singe page
of coded program.
4. The
program should be reliable.
- State
the limitation of the program.
- Incorporate
as many error messages as possible
- Use
security to prevent modification of the program by unauthorized
users.
|