I) Modularity
Our earlier discussion on top-down design suggests that a problem can be
decomposed into a number of modules that are simple enough for us to convert
into subprograms. Hence, the task of writing a large program is reduced
to the task of writing many small subprograms.
This modular approach has several advantages:
1)
A program of many small modules is easier to follow and modify than one
large program.
2)
It enables us to concentrate on one small problem at a time.
3)
Modules can be tested and debugged separately.
4)
It allows team programming, where several programmers work independently
on their own modules.
5)
Modules can be used by different programs.
We can say that the payroll program below
consists of three main modules, namely, Get data, Calculate wage and Output
total wage. For now, a module means a block of program segments.
program Payroll;
uses wincrt; var Total, Allowance, RegularWage, HourlyRate :real; NoOfHours, Overtime :integer; begin (* Get data *) write('Enter number of hours worked: '); readln(NoOfHours); write('Enter hourly rate: '); readln(Hourlyrate); (* Calculate wage *)
(* Output total wage *)
|
II) Readability
Throughout this book, programs are presented using the following conventions to enhance readability.
1)
Reserved words are in lowercase and blodface.
2)
Standard identifiers, standard functions and standard procedures are in
lowercase.
3)
User-defined identifiers are chosen to describe their purpose. Both uppercase
and lowercase are used with each word beginning with a capital letter.
4)
Consistentidentation styles are observed.
5)
Black lines are used to separate program modules or blocks.
6)
Documentation in the form of remark statements is included to aid understanding
of the program.