TOPIC 3.2. FEATURES OF
PROCEDURAL PROGRAMMING LANGUAGES
TOP-DOWN DESIGN
- Top-down design is the technique of breaking
down a problem into the major tasks to be performed; each of these tasks is
then further broken into separate subtasks, and so on until each subtask is
sufficiently simple to be written as a self-contained module or procedure.
- The program then consists of a series of calls
to these modules, which may themselves call other modules.
JACKSON STRUCTURE DIAGRAMS
- It is useful to have some way of representing
the structure of a program - how the modules all relate to form the whole
solution and a Jackson structure diagram is one way of doing this.
- When a program is large and complex it becomes
especially important to plan out the solution before doing any coding and a
structure diagram also serves a useful purpose as documentation when the
program is complete.
- The diagram below resembles a family tree, with
the main program statements written across the top line.

THE BUILDING BLOCKS OF A STRUCTURED PROGRAM
Only three different 'building blocks' or program
constructs are needed to write a structured program. These are:
- Sequence - in which one statement follows
another and the program executes them in the sequence given.
- Selection - 'if..then..else' is an example of
selection, where the next statement to be executed depends on the value of an
expression.
- Iteration - a section of the program is repeated
many times, as for example in the 'while..do' statement.
- Programs that are written using top-down
techniques and suing only the three constructs described are called structured
programs.
REPRESENTATION OF A LOOP
- Within the loop written, it is used to indicate
a section of code repeated may times.
- For example,
| while a<b do
begin
statement1
statement2
statement3
end {endwhile} |
REPRESENTATION OF SELECTION
- Selection is represented by a small circle in
each of the boxes representing the alternative paths.
- For example,
| if (answer = 'Y') or
(answer = 'y') then
statement 1
else
statement 2 |
MODULAR PROGRAMMING
- Any program that you write is likely to be
relatively short; however, in industry and commerce some problems will require
thousands or even tens of thousands of lines of code to solve.
- The importance of splitting up the problem into
a series of self-contained modules then becomes obvious.
- A module should not exceed 100 or so lines, and
preferably be short enough to fit on a single page; some modules may be only a
few lines.
ADVANTAGES OF MODULAR PROGRAMMING
- Some modules will be standard procedures used
again and again in different programs or parts of the same program; for
example, a routine to display a standard opening screen.
- A module is small enough o be understandable as
a unit of code. It is therefore easier to understand and debug, especially if
its purpose is clearly defined and documented.
- Program maintenance becomes easier because the
affected modules can be quickly identified and changed.
- In a very large project, several programmers may
be working on a single program. Using a modular approach, each programmer can
be given a specific set of modules to work on. This enables the whole program
to be finished sooner.
- More experienced programmers can be given the
more complex modules to write, and the junior programmers can work on the
simpler modules.
- Modules can be tested independently, thereby
shortening the time taken to get the whole program working.
- If a programmer leaves part way through a
project, it is easier for someone else to take over a set of self contained
modules.
- A large project becomes easier to monitor and
control.
BOTTOM-UP DESIGN
- When faced with a large and complex problem it
may be difficult to see how the whole thing can be down.
- It may be easier to attack parts of the problem
individually, taking the easier aspects first and thereby gaining the insight
and experience to tackle the more difficult tasks and finally to try and bolt
them all together to form the complete solution.
- This is called as a bottom-up approach.
- It suffers from the disadvantage that the parts
of the program may not fit together very easily, there may be a lack of
consistency between modules, and considerable re-programming may have to be
done.
RESOURCE:
P M Heatcote, [A level Computing, 3rd
Edition], Ashford Colour Press Ltd, 1996.