Lecture 1 A Survey of Programming Techniques
Lecture 1 A Survey of Programming Techniques
Roughly speaking, we can distinguish the following learning curve of someone who learns to program:
Unstructured programming,
procedural programming,
modular programming and
object-oriented programming.
Unstructured Programming
Usually, people start learning programming by writing small and simple programs consisting only of one main
program. Here main program stands for a sequence of commands or statements which modify data which
is global throughout the whole program.
As you should all know, this programming techniques provide tremendous disadvantages once the program gets
sufficiently large. For example, if the same statement sequence is needed at different locations within the
program, the sequence must be copied. This has lead to the idea to extract these sequences, name them and
offering a technique to call and return from these procedures.
Advantages
o Low Level access
o High Optimization
o Shorter size programs
Disadvantages
o Large programs highly complex
o Difficult to understand
o Repetition of code
Procedural Programming
With procedural programming you are able to combine returning sequences of statements into one single place.
A procedure call is used to invoke the procedure. After the sequence is processed, flow of control proceeds
right after the position where the call was made.
Execution of procedures. After processing flow of controls proceed where the call was made.
With introducing parameters as well as procedures of procedures ( subprocedures) programs can now be
written more structured and error free. For example, if a procedure is correct, every time it is used it produces
correct results. Consequently, in cases of errors you can narrow your search to those places which are not
proven to be correct.
Now a program can be viewed as a sequence of procedure calls. The main program is responsible to pass data to
the individual calls, the data is processed by the procedures and, once the program has finished, the resulting
data is presented. Thus, the flow of data can be illustrated as a hierarchical graph, a tree, as shown in Fig.
To sum up: Now we have a single program which is devided into small pieces called procedures. To enable
usage of general procedures or groups of procedures also in other programs, they must be separately available.
For that reason, modular programming allows grouping of procedures into modules.
Modular Programming
With modular programming procedures of a common
functionality are grouped together into separate modules.
A program therefore no longer consists of only one single
part. It is now devided into several smaller parts which
interact through procedure calls and which form the
whole program
Each module can have its own data. This allows each module to manage an internal state which is modified by
calls to procedures of this module. However, there is only one state per module and each module exists at most
once in the whole program.
Object-Oriented Programming
Object-oriented programming solves some of the problems just mentioned. In contrast to the other techniques,
we now have a web of interacting objects, each house-keeping its own state
Arrange following set of activities in a sensible order. Then split the related activities into three blocks called
modules. Then give each module a suitable title.
Eat breakfast
Get dressed
Drive to work
By structuring activities , we can change or improve one section without effecting the other.
For example we can improve the “Go to work “ by Listen to local traffic or weather report and decide whether
to go by bus or go by car, if going by car get the car and goto work else walk to the bus station and catch the
bus.
Another advantage is that we get the reusabale components.
In the same way oop structure the program into objects so that change in one object does not effect the
others.