Procedures, Parameters & Sub-programs

Satisfactory Essays
Procedures, Parameters & Sub-Programs

In any modern programming language, procedures play a vital role in the construction of any new software. These days, procedures are used instead of the old constructs of GOTO and GOSUB, which have since become obsolete.

Procedures provide a number of important features for the modern software engineer:- Programs are easier to write. Procedures save a large amount of time during software development as the programmer only needs to code a procedure once, but can use it a number of times. Procedures are especially useful in recursive algorithms where the same piece of code has to be executed over and over again.
The use of procedures allows a large and complex program to be broken up into a number of much smaller parts, each accomplished by a procedure. Procedures also provide a form of abstraction as all the programmer has to do is know how to call a procedure and what it does, not how it accomplishes the task.

Programs are easier to read. Procedures help to make programs shorter, and thus easier to read, by replacing long sequences of statements with one simple procedure call. By choosing goo procedure names, even the names of the procedures help to document the program and make it easier to understand.

Programs are easier to modify. When repeated actions are replaced by one procedure call, it becomes much easier to modify the code at a later stage, and also correct any errors. By building up the program in a modular fashion via procedures it becomes much easier to update and replace sections of the program at a later date, if all the code for the specific section is in a particular module. Programs take less time to compile. Replacing a sequence of statements with once simple procedure call usually reduces the compilation time of the program, so long as the program contains more than one reference to the procedure!

Object programs require less memory. Procedures reduce the memory consumption of the program in two ways. Firstly they reduce code duplication as the code only needs to be stored once, but the procedure can be called many times.
Secondly, procedures allow more efficient storage of data, because storage for a procedure's variables is allocated when the procedure is called and deallocated when it returns.

We can divide procedures into two groups:-

Function procedures, are procedures which compute a single value and whose calls appear in expressions

For example, the procedure ABS is a function procedure, when given a number x,
ABS computes the absolute value of x; a call of ABS appears in an expression,
Get Access