Sinclair QL Beginner's Manual page 40

Hide thumbs Also See for QL:
Table of Contents

Advertisement

CHAPTER 7 – SIMPLE PROCEDURES
If you were to try to write computer programs to solve complex problems you might find it difficult to
keep track of things. A methodical problem solver therefore divides a large or complex job into smaller
sections or tasks, and then divides these tasks again into smaller tasks, and so on until each can be
be easily tackled.
This is similar to the arrangement of complex human affairs. Successful government depends on a
delegation of responsibility. The Prime Minister divides the work amongst ministers, who divide it
further through the Civil Service until tasks can be done by individuals without further division. There
are complicating features such as common services and interplay between the same and different
levels, but the hierarchical structure is the dominant one.
A good programmer will also work in this way and a modern language like SuperBASIC which allows
properly named, well defined procedures will be much more helpful than older versions which do not
have such features.
The idea is that a separately named block of code should be written for a particular task. It doesn't
matter where the block of code is in the program. If it is there somewhere,the use of its name will:
activate the code
return control to the point in the program immediately after that use.
If a procedure, square, draws a square the scheme is as shown below:
In practice the separate tasks within a job can be identified and named before the definition code is
written. The name is all that is needed in calling the procedure so the main outline of the program can
be written before all the tasks are defined.
Alternatively if it is preferred, the tasks can be written first and tested. If it works you can then forget
the details and just remember the name and what the procedure does.
Example
The following example could quite easily be written without procedures but it shows they can be used
in a reasonably simple context. Almost any task can be broken down in a similar fashion which means
that you never have to worry about more than, say five to thirty lines at any one time. If you can write
thirty-line programs well and handle procedures, then you have the capability to write three-hundred-
line programs.
You can produce ready made buzz phrases for politicians or others who wish to give an impression of
technological fluency without actually knowing anything. Store the following words in three arrays and
then produce ten random buzz phrases.
adjec1$
Full
Systematic
Intelligent
adjec2$
fifth-generation
knowledge-based
compatible
noun$
systems
machines
computers

Advertisement

Table of Contents
loading

Table of Contents