PPL Lecture5
PPL Lecture5
(Lecture 5)
Subprograms
Fundamentals of Sub Programs
A subprogram definition is a description of the actions of the subprogram
abstraction. A subprogram call is an explicit request that the called subprogram
be executed. A subprogram is said to be active if, after having been called, it has
begun execution but has not yet completed that execution. The two fundamental
types of the subprograms are:
1) Procedures
2) Functions
3. What access controls are provided and how such controls are specified.
Ada
Packages can also be generic, so we can construct generic, or parameterized,
abstract data types.
The Ada stack abstract data type example suffers two restrictions:
(1) Stacks of its type can store only integer type elements, and
(2) the stacks can have only up to 100 elements.
Encapsulation Constructs
When the size of a program reaches beyond a few thousand lines, two practical
problems become evident. From the programmer’s point of view, having such a
program appear as a single collection of subprograms or abstract data type
definitions does not impose an adequate level of organization on the program to
keep it intellectually manageable. The second practical problem for larger
programs is recompilation. For relatively small programs, recompiling the whole
program after each modification is not costly. But for large programs, the cost of
recompilation is significant. So, there is an obvious need to find ways to avoid
recompilation of the parts of a program that are not affected by
Encapsulations are often placed in libraries and made available for reuse in
programs other than those for which they were written. People have been writing
programs with more than a few thousand lines for at least the last 50 years, so
techniques for providing encapsulations have been evolving for some time.
Naming Encapsulations
Libraries are the origin of the same kind of naming problems. Over the past two
decades, large software systems have become progressively more dependent on
libraries of supporting software. Nearly all software written in contemporary
programming languages requires the use of large and complex standard libraries,
in addition to application-specific libraries. This widespread use of multiple
libraries has necessitated new mechanisms for managing names.
Naming encapsulations define name scopes that assist in avoiding these name
conflicts. Each library can create its own naming encapsulation to prevent its
names from conflicting with the names defined in other libraries or in client code.
Each logical part of a software system can create a naming encapsulation with the
same purpose.
Naming encapsulations are logical encapsulations, in the sense that they need not
be contiguous. Several different collections of code can be placed in the same
namespace, even though they are stored in different places.