Concepts of Programming Languages

(Sean Pound) #1
11.4 Language Examples 485

with Stack_Pack;
use Stack_Pack;
procedure Use_Stacks is
Topone : Integer;
Stack : Stack_Type; -- Creates a Stack_Type object
begin
Push(Stack, 42);
Push(Stack, 17);
Topone := Top(Stack);
Pop(Stack);

...
end Use_Stacks;


A stack is a silly example for most contemporary languages, because sup-
port for stacks is included in their standard class libraries. However, stacks
provide a simple example we can use to allow comparisons of the languages
discussed in this section.

11.4.1.4 Evaluation
Ada, along with Modula-2, was the first commercial language to support
abstract data types.^2 Although Ada’s design of abstract data types may seem
complicated and repetitious, it clearly provides what is necessary.

11.4.2 Abstract Data Types in C++
C++, which was first released in 1985, was created by adding features to C. The
first important additions were those to support object-oriented programming.
Because one of the primary components of object-oriented programming is
abstract data types, C++ obviously is required to support them.
While Ada provides an encapsulation that can be used to simulate abstract
data types, C++ provides two constructs that are very similar to each other, the
class and the struct, which more directly support abstract data types. Because
structs are most commonly used when only data is included, we do not discuss
them further here.
C++ classes are types; as stated previously, Ada packages are more gen-
eralized encapsulations that can define any number of types. A program unit
that gains visibility to an Ada package can access any of its public entities
directly by their names. A C++ program unit that declares an instance of a
class can also access any of the public entities in that class, but only through
an instance of the class. This is a cleaner and more direct way to provide
abstract data types.


  1. The language CLU, which was an academic research language, rather than a commercial
    language, was the first to support abstract data types.

Free download pdf