What is Ada?

Ada is a computer programming language originally designed to support the construction of long-lived, highly reliable software systems. Its design emphasizes readability, avoids error-prone notation, encourages reuse and team coordination, and it is designed to be efficiently implementable.

A significant advantage of Ada is its reduction of debugging time. Ada tries to catch as many errors as reasonably possible, as early as possible. Many errors are caught at compile-time by Ada that aren't caught or are caught much later by other computer languages. Ada programs also catch many errors at run-time if they can't be caught at compile-time (this checking can be turned off to improve performance if desired). In addition, Ada includes a problem (exception) handling mechanism so that these problems can be dealt with at run-time.

What exactly are Ada's capabilities?

  1. Packages (modules) of related types, objects, and operations can be defined.
  2. Packages and types can be made generic (parameterized through a template) to help create reusable components.
  3. Errors can be signalled as exceptions and handled explicitly. Many serious errors (such as computational overflow and invalid array indexes) are automatically caught and handled through this exception mechanism, improving program reliability.
  4. Tasks (multiple parallel threads of control) can be created and communicate. This is a major capability not supported in a standard way by many other languages.
  5. Data representation can be precisely controlled to support systems programming.
  6. A predefined library is included; it provides input/output (I/O), string manipulation, numeric functions, a command line interface, and a random number generator (the last two were available in Ada 83, but are standardized in Ada 95).
  7. Object-oriented programming is supported (this is a new feature of Ada 95). In fact, Ada 95 is the first internationally standardized object-oriented programming language.
  8. Interfaces to other languages (such as C, Fortran, and COBOL) are included in the language (these have been significantly enhanced in Ada 95). At least one Ada compiler (from Intermetrics) can generate Java Virtual Machine (J-code) from Ada, so people can use Ada to

 

History of Ada Language

 

The first programmer Lady Lovelace programmed in the Ada Programming Language around 1850. She was born in 1815 and die in 1852. She worked with Charles Babbage, who had created a “difference engine” that could be programmed much like a Jacquard loom. The language’s name Ada was chosen after because Ada(Lady Lovelace) often “programmed” the difference engine.

 

Development of Ada 83

 

After more than hundred years, Ada Language came to the attention of the Computer Science Community. In 1974, many groups began to study specially the army started to implement Ada. The army called it, Language for Real Time Systems; the navy called CS4 Program; the Air Force effort was named the High Order Language Standardization Study.

The overall result of those army projects led to the first military standard specification MIL-STD-1815.

And in 1983 Ada/Ed was standardized to ANSI document.

 

Last Release of Ada 95

 

            Ada 95 was designed and developed from an international process of unprecedented scale for a programming language. This revision retains the original version of Ada 83. Ada 95 provides support for object oriented programming.

Simple Program

Here's a simple program in Ada that simply prints a message, often called the hello, world! program (for the moment, ignore the buttons below the sample program):

 

Print a simple message to demonstrate a trivial Ada program.

 

with Ada.Text_IO;

procedure Hello is

begin

 Ada.Text_IO.Put_Line("Hello, world!");

end Hello;

 

 

Here's an explanation of each line:

  1. The first line illustrates a comment; Ada comments begin with ``--'' and end at the end of the line (C++ comments that begin with // work the same way).
  2. The second line illustrates a with clause, which specifies the library units (other items) that we need. This particular with clause specifies that we need Ada.Text_IO. The library unit Ada.Text_IO is a predefined library unit that provides operations to perform basic text input and output.
  3. The third line states that we're defining a new procedure named Hello. Note that in Ada there's nothing special about the name of the main program (in C and C++, it must be called main, and in Pascal, it must be specially identified as the program).
  4. The fourth line just has the keyword begin, which begins the definition of the procedure Hello.
  5. The fifth line calls Ada.Text_IO's procedure Put_Line, which prints a line to the current output (usually the screen) and then ends the current line. The basic syntax for calling a procedure is to give the library unit name, a period, the name of the procedure, and then list the parameters (if any) enclosed in parentheses (we'll see how to simplify this soon). In Ada, strings are surrounded by double quotes (the same as C and C++; Pascal uses single quotes).
  6. The last line ends the definition of the procedure.

Ada terminates each statement with a semicolon. This is like C and C++ and unlike standard Pascal (which uses semicolons as statement separators).

Simple Variable, Integers, Parameters and Exceptions

Let's create a program to show what a simple variable and parameter-passing look like. This program will print out powers of 2, starting with 1, ``forever''. We'll call this program procedure Compute.

Inside this procedure create a local procedure called Double which doubles any number given to it, and a local integer variable named `X'.

Demonstrate a trivial procedure, with another nested inside.

 

with Ada.Text_IO, Ada.Integer_Text_IO;

use Ada.Text_IO, Ada.Integer_Text_IO;

 

procedure Compute is

 

 procedure Double(Item : in out Integer) is

 begin -- procedure Double.

   Item := Item * 2;

 end Double;

 

 X : Integer := 1;   -- Local variable X of type Integer.

 

begin -- procedure Compute

 loop

  Put(X);

  New_Line;

  Double(X);

 end loop;

end Compute;

Review of Basic Ada Structures

Let's briefly review what we've learned so far:

  1. Logically, Ada programs are composed of a set of program units.
  2. There are different kinds of program units; the ones we've concentrated on are subprograms and packages.
  3. Subprograms define processing algorithms. Subprograms can be procedures or functions.
  4. Packages are the main Ada structuring tool used to group things together.
  5. In general, a program unit has two parts, a declaration and a body. Sometimes a declaration is also called a specification.
  6. Ada compilers compile compilation units. A compilation unit is either a program unit's declaration or body, preceded by a context clause.
  7. A context clause is a set of with clauses (that state what other program units are needed) and/or use clauses (the program units to search by default).

Type Extension:

            Type extension in ADA 95 is achieved using ‘tagged records’.  Tagged records allow the original ADA record type to be extended from a foundation record.  The foundation record must be specified as tagged.

 

For example:

 

package people is

type sex is (male, female);

type person is tagged record

     name:string(1..35);

     gender:sex;

end record;

function age (p:in person) return natural;

end people;

 

Now suppose we have another package call “school” that uses specification from package “people”:

 

packeage school is

type janitor is new person with null record;

type teacher isnew person with record

     subject:string(1..5);

end record;

 

type head_master is new teacher with record

     off_tel:natural;

     room-num:natural;

end record;

end school;

 

 

Type “janitor” is extended from the foundation type “person.”  It has the fields “name”, “gender”, but no additional fields are added since we wrote “ with null record”.

 

Type “teacher” is extended from the foundation type “person.”  The extension “teacher” has the basic fields “name” and “gender” as the foundation record type “person.”  In addition to the basic fields, a new field, “subject” is added.  This is called type extension and is only possible if the base or foundation type (person in this case) is declared as tagged.

 

Type “head_master” is extended from type “teacher”.  Since the base type of “teacher” is declared as tagged, it is possible to add fields to type “head_master”.  In this case, we have added the fields “off_tel” and “room_num.”

 

Tagged Private:

 

When using tagged private, the foundation type must be private and allows users to extend it.

 

For example:

 

Package new_people is

type sex is (male, female);

type person is tagged private;

function age (p:person) return natural;

 

private

     type person is tagged record

          name:string(1..5);

          gender:sex;

     end record;

end new_people;

 

Note that the type “person” is tagged private.  That means it allows the user of the package “new_people” to extend the type “person” without knowing the details of the type.

 

For example:

 

with new_people; use new_people;

package user is

     type star is new_person with record

          cosmetic_surgery:boolean;

     end record;

…..

end user;

 

Type “star” extends “new_person” without knowing the details of the type (eg. What fields it contains).

 

Polymorphism:

            In ADA95, if we have a tagged type T, then we automatically have an associated type T’class which contains the union of all types derived from the root type T

 

For example, from the tagged type “person”, we have person’class which contains the union of all types derived from the root type “persion” (janitor, teacher, head_master).