



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Modern Programing Language is about different languages of today era. It explains pros and cons of some new languages and their differences with old ones. Languages like java, c sharp, c plus plus, c, fotran are included in this course. This lecture handout is about: Extensible, Relationship, Stack, Integer, Object, Orientation, Ada, Tagged, Positive, Push
Typology: Exercises
1 / 6
This page cannot be seen from the preview
Don't miss anything!




The primary structure used for encapsulation in Ada is called a package. Packages are used to group data and subprograms. Packages can be hierarchical, allowing a structured and extensible relationship for data and code. All the standard Ada libraries are defined within packages.
Package definitions usually consist of two parts: package specification and package body. Package bodies can also declare and define data types, variables, constants, functions, and procedures not declared in the package specification. In the following example, a STACK package is defined. We first the have the package specification as follows:
package STACK is procedure PUSH (x : INTEGER); function POP return INTEGER; end STACK;
The body of the package is shown below.
package body STACK is MAX: constant := 100; S : array (1..MAX) of INTEGER; TOP : INTEGER range 0..MAX;
procedure PUSH (x : INTEGER) is begin TOP := TOP + 1; S(TOP) := x; end PUSH;
function POP return integer is TOP := TOP - 1; return S(TOP + 1); end POP; begin TOP := 0; end STACK;
Once defined, a package can be used in the client program as follows:
with STACK; use STACK; procedure myStackExample is I, O : integer; begin … push(i); … O := pop; … end myStackExample;
Object-Orientation – The Ada Way Ada provides tools and constructs for extending types through inheritance. In many object oriented languages the concept of a class is overloaded. It is both the unit of encapsulation and a type definition. Ada separates these two concepts. Packages are used for encapsulation and Tagged types are used to define extensible types.
Tagged Type
A tagged type is like a record which can be used to declare objects. Following is an example of a tagged type:
type Person is tagged record Name : String(1..20); Age : Natural; end record;
Such a type definition is performed in a package. Immediately following the type definition must be the procedures and functions comprising the primitive operations defined for this type. Primitive operations must have one of its parameters be of the tagged type, or for functions the return value can be an instance of the tagged type. It allows you to overload functions based upon their return type. It may be noted that C++ and Java do not allow you to overload based upon the return type of a function.
Extending Tagged Types Just like classes in C++, the tagged type can be extended by making a new tagged record based upon the original type as shown below:
type Employee is new Person with record Employee_Id : Positive; Salary : Float; end record;
In this example, type Employee inherits all the fields and primitive operations of type Person.
Concurrency
Ada Tasking allows the initiation of concurrent tasks which initiates several parallel activities which cooperate as needed. Its syntax is similar to packages as shown below:
task thisTask is …-- interfaces end thisTask;
task body thisTask is … end thisTask;
task simpleTask; -- this task does not provide an interface to other tasks
Here is a very simple example that demonstrates the concept of parallel processing. In this example we specify COOKING a procedure composed of three steps.
procedure COOKING is begin cookMeat; cookRice; cookPudding; end COOKING;
As these steps can be carried out in parallel, we define tasks for these tasks as shown below:
procedure COOKING is task cookMeat; task body cookMeat is begin -- follow instructions for cooking meat end cookMeat;
task cookRice; task body cookRice is begin -- follow instructions for cooking rice end cookRice;
begin cookPudding; end COOKING;
Other Features Ada is a HUGE language and we have looked at may be only 25-30% of this language. It is to be remembered that the main objective of the Ada design was to incorporate the contemporary software engineering knowledge in it. In general, software development time is: 10% design, 10% coding, 60% debug and 20% test. Last 80% of the project is spent trying to find and eliminate mistakes made in the first 20% of the project. Therefore Ada promised to spend 20% time in design, 60% in coding, 10% in debug, and 10% in testing. Therefore cutting the entire cycle time in half!
I would like to finish with a quote from Robert Dewar: “ When Roman engineers built a bridge, they had to stand under it while the first legion marched across. If programmers today worked under similar ground rules, they might well find themselves getting much more interested in Ada. “