Ada is a
structuredStructured programming is a programming paradigm aimed on improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures and for and while loops - in contrast to using simple tests and jumps such as the goto statement which could...
, statically typed,
imperativeIn computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...
,
wide-spectrumA wide-spectrum language is a programming language designed to be simultaneously a low-level and a high-level language—possibly a non-executable specification language. Wide-spectrum languages are designed to support a programming methodology based on program refinement.The concept was...
, and
object-orientedObject-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
high-level
computerComputer programming is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages. The purpose of programming is to create a program that performs specific operations or exhibits a...
programming languageA programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
, extended from
PascalPascal is an influential imperative and procedural programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.A derivative known as Object Pascal...
and other languages. It has strong built-in language support for explicit concurrency, offering tasks, synchronous message passing (via guarded task entries), protected objects (a monitor-like construct with additional guards as in conditional critical regions) and nondeterminism (via
select statements).
Ada was originally designed by a team led by
Jean IchbiahJean David Ichbiah was a French-born computer scientist and the chief designer of Ada, a general-purpose, strongly typed programming language with certified validated compilers....
of
CII Honeywell Bull-External links:* * — Friends, co-workers and former employees of Bull and Honeywell* *...
under contract to the
United States Department of DefenseThe United States Department of Defense is the U.S...
(DoD) from 1977 to 1983 to supersede the hundreds of programming languages then used by the DoD. Ada is strongly typed and compilers are validated for reliability in mission-critical applications, such as
avionicsAvionics are electronic systems used on aircraft, artificial satellites and spacecraft.Avionic systems include communications, navigation, the display and management of multiple systems and the hundreds of systems that are fitted to aircraft to meet individual roles...
software. Ada is an international standard; the current version (known as Ada 2005) is defined by joint ISO/ANSI standard, combined with major Amendment ISO/IEC 8652:1995/Amd 1:2007.
Ada was named after
Ada LovelaceAugusta Ada King, Countess of Lovelace , born Augusta Ada Byron, was an English writer chiefly known for her work on Charles Babbage's early mechanical general-purpose computer, the analytical engine...
(1815–1852), who is sometimes credited as being the first computer programmer.
Features
Ada was originally targeted at
embeddedAn embedded system is a computer system designed for specific control functions within a larger system. often with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. By contrast, a general-purpose computer, such as a personal...
and
real-timeIn computer science, real-time computing , or reactive computing, is the study of hardware and software systems that are subject to a "real-time constraint"— e.g. operational deadlines from event to system response. Real-time programs must guarantee response within strict time constraints...
systems. The Ada 95 revision, designed by S. Tucker Taft of
IntermetricsIntermetrics, Inc. was a software company founded in Cambridge, Massachusetts in 1969 by several veterans of M.I.T.'s Instrumentation Laboratory who had worked on the software for NASA's Apollo Program including the Apollo Guidance Computer....
between 1992 and 1995, improved support for systems, numerical, financial, and
object-oriented programmingObject-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
(OOP).
Notable features of Ada include: strong typing,
modularity mechanismsModular programming is a software design technique that increases the extent to which software is composed of separate, interchangeable components called modules by breaking down program functions into modules, each of which accomplishes one function and contains everything necessary to accomplish...
(packages),
run-time checkingRuntime checking is a mechanism of a programming language to check for errors at runtime, e.g. arithmetic overflows or invalid type casts. Most times an exception is thrown and/or the program is terminated, instead of ignoring this failure as it is done in C, C++ etc.Runtime checking is often...
,
parallel processingParallel processing is the ability to carry out multiple operations or tasks simultaneously. The term is used in the contexts of both human cognition, particularly in the ability of the brain to simultaneously process incoming stimuli, and in parallel computing by machines.-Parallel processing by...
(tasks, synchronous
Message passingMessage passing in computer science is a form of communication used in parallel computing, object-oriented programming, and interprocess communication. In this model, processes or objects can send and receive messages to other processes...
, protected objects and nondeterministic select statements),
exception handlingException handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution....
, and
genericIn a broad definition, generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters...
s. Ada 95 added support for
object-oriented programmingObject-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
, including
dynamic dispatchIn computer science, dynamic dispatch is the process of mapping a message to a specific sequence of code at runtime. This is done to support the cases where the appropriate method can't be determined at compile-time...
.
The syntax of Ada is simple, consistent and readable. It minimizes choices of ways to perform basic operations, and prefers English keywords (e.g. "or else") to symbols (e.g. "||"). Ada uses the basic mathematical symbols (i.e.: "+", "-", "*" and "/") for basic mathematical operations but avoids using other symbols. Code blocks are delimited by words such as "declare", "begin" and "end", whereas the "end" (in most cases) is followed by the identifier of the block it closes (e.g.
if.. end if,
loop ... end loop). In the case of conditional blocks this avoids a
dangling elseThe dangling else is a problem in computer programming in which a seemingly well-defined statement can become ambiguous. In many programming languages one may write conditionally executed code in two forms: the if-then form, and the if-then-else form:...
that could pair with the wrong nested if-expression in other languages; for example, C or Java.
Ada is designed for development of very large software systems. Ada packages can be compiled separately, and furthermore, Ada package specifications (the package interface) can be compiled separately without the implementation to check for consistency - this makes it possible to detect problems early during the design phase, before implementation starts.
A large number of compile-time checks are supported to help avoid bugs that would not be detectable until run-time in some other languages or would require explicit checks to be added to the source code. For example, the syntax requires explicitly named closing of blocks to prevent errors due to mismatched end tokens. The adherence to strong typing allows detection of many common software errors (wrong parameters, range violations, invalid references, mismatched types, etc.) either during compile-time, or otherwise during run-time. As concurrency is part of the language specification, the compiler can in some cases detect potential deadlocks. Compilers also commonly check for misspelled identifiers, visibility of packages, redundant declarations, etc. and can provide warnings and useful suggestions on how to fix the error.
Ada also supports run-time checks to protect against access to unallocated memory,
buffer overflowIn computer security and programming, a buffer overflow, or buffer overrun, is an anomaly where a program, while writing data to a buffer, overruns the buffer's boundary and overwrites adjacent memory. This is a special case of violation of memory safety....
errors, range violations,
off-by-one errorAn off-by-one error is a logical error involving the discrete equivalent of a boundary condition. It often occurs in computer programming when an iterative loop iterates one time too many or too few...
s, array access errors, and other detectable bugs. These checks can be disabled in the interest of runtime efficiency, but can often be compiled efficiently. It also includes facilities to help program verification. For these reasons, Ada is widely used in critical systems, where any
anomalyIn software testing, a software anomaly is anything that differs from expectation. This expectation can result from many things like from a document or from a person's view or experiences In software testing, a software anomaly is anything that differs from expectation. This expectation can...
might lead to very serious consequences, e.g., accidental death, injury or severe financial loss. Examples of systems where Ada is used include
avionicsAvionics are electronic systems used on aircraft, artificial satellites and spacecraft.Avionic systems include communications, navigation, the display and management of multiple systems and the hundreds of systems that are fitted to aircraft to meet individual roles...
, railways, banking, military and space technology.
Ada's dynamic
memory managementMemory management is the act of managing computer memory. The essential requirement of memory management is to provide ways to dynamically allocate portions of memory to programs at their request, and freeing it for reuse when no longer needed. This is critical to the computer system.Several...
is high-level and type-safe. Ada does not have generic (and vague) "pointers"; nor does it implicitly declare any pointer type. Instead, all dynamic memory allocation and deallocation must take place through explicitly declared
access types.
Each access type has an associated
storage pool that handles the low-level details of memory management; the programmer can either use the default storage pool or define new ones (this is particularly relevant for
Non-Uniform Memory AccessNon-Uniform Memory Access is a computer memory design used in Multiprocessing, where the memory access time depends on the memory location relative to a processor...
). It is even possible to declare several different access types that all designate the same type but use different storage pools.
Also, the language provides for
accessibility checks, both at compile time and at run time, that ensures that an
access value cannot outlive the type of the object it points to.
Though the semantics of the language allow automatic
garbage collectionIn computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program...
of inaccessible objects, most implementations do not support it by default, as it would cause unpredictable behaviour in real-time systems. Ada does support a limited form of region-based storage management; also, creative use of storage pools can provide for a limited form of automatic garbage collection, since destroying a storage pool also destroys all the objects in the pool.
Ada was designed to use the English language standard for
commentsIn computer programming, a comment is a programming language construct used to embed programmer-readable annotations in the source code of a computer program. Those annotations are potentially significant to programmers but typically ignorable to compilers and interpreters. Comments are usually...
: the em-dash, as a double-
dashA dash is one of several kinds of punctuation mark. Dashes appear similar to hyphens, but differ from them primarily in length, and serve different functions. The most common versions of the dash are the en dash and the em dash .-Common dashes:...
("--") to denote comment text. Comments stop at end of line, so there is no danger of unclosed comments accidentally voiding whole sections of source code. Comments can be nested: prefixing each line (or column) with "--" will skip all that code, while being clearly denoted as a column of repeated "--" down the page. There is no limit to the nesting of comments, thereby allowing prior code, with commented-out sections, to be commented-out as even larger sections. All
UnicodeUnicode is a computing industry standard for the consistent encoding, representation and handling of text expressed in most of the world's writing systems...
characters are allowed in comments, such as for symbolic formulas (E[0]=m×c²). To the compiler, the double-dash is treated as end-of-line, allowing continued parsing of the language as a
context-free grammarIn formal language theory, a context-free grammar is a formal grammar in which every production rule is of the formwhere V is a single nonterminal symbol, and w is a string of terminals and/or nonterminals ....
.
The semicolon (";") is a statement terminator, and the null or no-operation statement is
null;. A single
; without a statement to terminate is not allowed. This allows for a better quality of error messages.
Code for complex systems is typically maintained for many years, by programmers other than the original author. It can be argued that these language design principles apply to most software projects, and most phases of software development, but when applied to complex, safety critical projects, benefits in correctness, reliability, and maintainability take precedence over (arguable) costs in initial development.
Unlike most
ISOThe International Organization for Standardization , widely known as ISO, is an international standard-setting body composed of representatives from various national standards organizations. Founded on February 23, 1947, the organization promulgates worldwide proprietary, industrial and commercial...
standards, the Ada language definition (known as the
Ada Reference Manual or
ARM, or sometimes the
Language Reference Manual or
LRM) is
free contentFree content, or free information, is any kind of functional work, artwork, or other creative content that meets the definition of a free cultural work...
. Thus, it is a common reference for Ada programmers and not just programmers implementing Ada compilers. Apart from the reference manual, there is also an extensive rationale document which explains the language design and the use of various language constructs. This document is also widely used by programmers. When the language was revised, a new rationale document was written.
One notable
free softwareFree software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...
tool that is used by many Ada programmers to aid them in writing Ada source code is
GPS, the
GNAT Programming StudioGNAT Programming Studio is a free multi-language integrated development environment by AdaCore. GPS uses compilers from the GNU Compiler Collection, taking its name from GNAT, the GNU compiler for the Ada programming language.GPS is cross-platform, running on Linux, Microsoft Windows and Solaris...
.
History
In the 1970s, the
US Department of DefenseThe United States Department of Defense is the U.S...
(DoD) was concerned by the number of different programming languages being used for its embedded computer system projects, many of which were obsolete or hardware-dependent, and none of which supported safe modular programming. In 1975, a
working groupA working group is an interdisciplinary collaboration of researchers working on new research activities that would be difficult to develop under traditional funding mechanisms . The lifespan of the WG can last anywhere between a few months and several years...
, the
High Order Language Working GroupThe High Order Language Working Group was a working group instrumental in developing the Ada computer programming language. The group was established in 1975 with the goal of establishing a single high level programming language appropriate for United States Department of Defense real-time...
(HOLWG), was formed with the intent to reduce this number by finding or creating a programming language generally suitable for the department's requirements. The result was Ada. The total number of high-level programming languages in use for such projects fell from over 450 in 1983 to 37 by 1996.
The HOLWG working group crafted the
Steelman language requirementsThe Steelman language requirements were a set of requirements which a high-level general-purpose programming language should meet, created by the United States Department of Defense in The Department of Defense Common High Order Language program in 1978...
, a series of documents stating the requirements they felt a programming language should satisfy. Many existing languages were formally reviewed, but the team concluded in 1977 that no existing language met the specifications.
Requests for proposals for a new programming language were issued and four contractors were hired to develop their proposals under the names of Red (
IntermetricsIntermetrics, Inc. was a software company founded in Cambridge, Massachusetts in 1969 by several veterans of M.I.T.'s Instrumentation Laboratory who had worked on the software for NASA's Apollo Program including the Apollo Guidance Computer....
led by Benjamin Brosgol), Green (CII Honeywell Bull, led by
Jean IchbiahJean David Ichbiah was a French-born computer scientist and the chief designer of Ada, a general-purpose, strongly typed programming language with certified validated compilers....
), Blue (SofTech, led by
John Goodenough), and Yellow (
SRI InternationalSRI International , founded as Stanford Research Institute, is one of the world's largest contract research institutes. Based in Menlo Park, California, the trustees of Stanford University established it in 1946 as a center of innovation to support economic development in the region. It was later...
, led by Jay Spitzen). In April 1978, after public scrutiny, the Red and Green proposals passed to the next phase. In May 1979, the Green proposal, designed by Jean Ichbiah at CII Honeywell Bull, was chosen and given the name Ada—after
Augusta Ada, Countess of LovelaceAugusta Ada King, Countess of Lovelace , born Augusta Ada Byron, was an English writer chiefly known for her work on Charles Babbage's early mechanical general-purpose computer, the analytical engine...
. This proposal was influenced by the programming language LIS that Ichbiah and his group had developed in the 1970s. The preliminary Ada reference manual
was published in ACM SIGPLAN Notices in June 1979. The Military Standard reference manual was approved on December 10, 1980 (
Ada LovelaceAugusta Ada King, Countess of Lovelace , born Augusta Ada Byron, was an English writer chiefly known for her work on Charles Babbage's early mechanical general-purpose computer, the analytical engine...
's birthday), and
given the number MIL-STD-1815 in honor of Ada Lovelace's birth year. In 1981,
C. A. R. HoareSir Charles Antony Richard Hoare , commonly known as Tony Hoare or C. A. R. Hoare, is a British computer scientist best known for the development of Quicksort, one of the world's most widely used sorting algorithms...
took advantage of his
Turing AwardThe Turing Award, in full The ACM A.M. Turing Award, is an annual award given by the Association for Computing Machinery to "an individual selected for contributions of a technical nature made to the computing community. The contributions should be of lasting and major technical importance to the...
speech to criticize Ada for being overly complex and hence unreliable, but subsequently seemed to recant in the foreword he wrote for an Ada textbook.
Ada attracted much attention from the programming community as a whole during its early days. Its backers and others predicted that it might become a dominant language for general purpose programming and not just defense-related work. Ichbiah publicly stated that within ten years, only two programming languages would remain, Ada and Lisp. Early Ada compilers struggled to implement the large, complex language, and both compile-time and run-time performance tended to be slow and tools primitive. Compiler vendors expended most of their efforts in passing the massive, language-conformance-testing, government-required "ACVC" validation suite that was required in another novel feature of the Ada language effort.
The first validated Ada implementation was the NYU Ada/ED translator, certified on April 11, 1983. NYU Ada/ED was implemented in the high-level set language
SETLSETL is a very-high level programming language based on the mathematical theory of sets. It was originally developed by Jack Schwartz at the NYU Courant Institute of Mathematical Sciences in the late 1960s....
.
In 1987, the US Department of Defense began to require the use of Ada (the
Ada mandate) for every software project where new code was more than 30% of result, though exceptions to this rule were often granted.
By the late 1980s and early 1990s, Ada compilers had improved in performance, but there were still barriers to full exploitation of Ada's abilities, including a tasking model that was different from what most real-time programmers were used to.
The Department of Defense Ada mandate was effectively removed in 1997, as the DoD began to embrace COTS (
commercial off-the-shelfIn the United States, Commercially available Off-The-Shelf is a Federal Acquisition Regulation term defining a nondevelopmental item of supply that is both commercial and sold in substantial quantities in the commercial marketplace, and that can be procured or utilized under government contract...
) technology. Similar requirements existed in other NATO countries.
Because of Ada's safety-critical support features, it is now used not only for military applications, but also in commercial projects where a software bug can have severe consequences, e.g. aviation and
air traffic controlAir traffic control is a service provided by ground-based controllers who direct aircraft on the ground and in the air. The primary purpose of ATC systems worldwide is to separate aircraft to prevent collisions, to organize and expedite the flow of traffic, and to provide information and other...
, commercial rockets (e.g. Ariane 4 and 5),
satelliteIn the context of spaceflight, a satellite is an object which has been placed into orbit by human endeavour. Such objects are sometimes called artificial satellites to distinguish them from natural satellites such as the Moon....
s and other space systems, railway transport and banking.
For example, the
fly-by-wireA conventional fixed-wing aircraft flight control system consists of flight control surfaces, the respective cockpit controls, connecting linkages, and the necessary operating mechanisms to control an aircraft's direction in flight...
system software in the
Boeing 777The Boeing 777 is a long-range, wide-body twin-engine jet airliner manufactured by Boeing Commercial Airplanes. It is the world's largest twinjet and is commonly referred to as the "Triple Seven". The aircraft has seating for over 300 passengers and has a range from , depending on model...
was written in Ada. The Canadian Automated Air Traffic System was written in 1 million lines of Ada (
SLOCSource lines of code is a software metric used to measure the size of a software program by counting the number of lines in the text of the program's source code...
count). It featured advanced distributed processing, a distributed Ada database, and object-oriented design. Ada is also used in other air traffic systems, e.g. the UK’s next-generation Interim Future Area Control Tools Support (iFACTS) air traffic control system is designed and implemented using SPARK Ada
It is also used in the
FrenchThe French Republic , The French Republic , The French Republic , (commonly known as France , is a unitary semi-presidential republic in Western Europe with several overseas territories and islands located on other continents and in the Indian, Pacific, and Atlantic oceans. Metropolitan France...
TVM in-
cab signallingCab signalling is a railway safety system that communicates track status information to the cab, crew compartment or driver's compartment of a locomotive, railcar or multiple unit, where the train driver or engine driver can see the information....
system on the
TGVThe TGV is France's high-speed rail service, currently operated by SNCF Voyages, the long-distance rail branch of SNCF, the French national rail operator....
high speed rail system, and the metro suburban trains in Paris, London, Hong Kong and New York City.
Standardization
The language became an
ANSIThe American National Standards Institute is a private non-profit organization that oversees the development of voluntary consensus standards for products, services, processes, systems, and personnel in the United States. The organization also coordinates U.S. standards with international...
standard in 1983 (
ANSI/MIL-STD 1815A), and without any further changes became
an
ISO standardInternational standards are standards developed by international standards organizations. International standards are available for consideration and use, worldwide...
in 1987 (ISO-8652:1987). This version of the language is commonly known as Ada 83, from the date of its adoption by ANSI, but is sometimes referred to also as Ada 87, from the date of its adoption by ISO.
Ada 95, the joint ISO/ANSI standard (
ISO-8652:1995) was published in February 1995, making Ada 95 the first ISO standard object-oriented programming language. To help with the standard revision and future acceptance, the US Air Force funded the development of the
GNATGNAT is a free-software compiler for the Ada programming language which forms part of the GNU Compiler Collection. It supports all versions of the language, i.e. Ada 2005, Ada 95 and Ada 83; it allows already some constructs of Ada 2012...
CompilerA compiler is a computer program that transforms source code written in a programming language into another computer language...
. Presently, the GNAT Compiler is part of the
GNU Compiler CollectionThe GNU Compiler Collection is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain...
.
Work has continued on improving and updating the technical content of the Ada programming language. A Technical Corrigendum to Ada 95 was published in October 2001, and a major Amendment,
ISO/IEC 8652:1995/Amd 1:2007, the current version of the standard, was published on March 9, 2007. Work on the next significant Ada Amendment is planned to be completed by 2012.(
ISO/IEC 8652:201z Ed. 3)
Other related standards include ISO 8651-3:1988
Information processing systems—Computer graphics—Graphical Kernel System (GKS) language bindings—Part 3: Ada.
Language constructs
Ada is an
ALGOLALGOL is a family of imperative computer programming languages originally developed in the mid 1950s which greatly influenced many other languages and became the de facto way algorithms were described in textbooks and academic works for almost the next 30 years...
-like programming language featuring control structures with reserved words such as
if,
then,
else,
while,
for, and so on. However, Ada also has many data structuring facilities and other abstractions which were not included in the original
ALGOL 60ALGOL 60 is a member of the ALGOL family of computer programming languages. It gave rise to many other programming languages, including BCPL, B, Pascal, Simula, C, and many others. ALGOL 58 introduced code blocks and the begin and end pairs for delimiting them...
, such as
type definitionsA type system associates a type with each computed value. By examining the flow of these values, a type system attempts to ensure or prove that no type errors can occur...
,
recordIn computer science, a record is an instance of a product of primitive data types called a tuple. In C it is the compound data in a struct. Records are among the simplest data structures. A record is a value that contains other values, typically in fixed number and sequence and typically indexed...
s, pointers,
enumerationIn computer programming, an enumerated type is a data type consisting of a set of named values called elements, members or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language...
s. Such constructs were in part inherited or inspired from
PascalPascal is an influential imperative and procedural programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.A derivative known as Object Pascal...
.
"Hello, world!" in Ada
A common example of a language's syntax is the
Hello world programA "Hello world" program is a computer program that outputs "Hello world" on a display device. Because it is typically one of the simplest programs possible in most programming languages, it is by tradition often used to illustrate to beginners the most basic syntax of a programming language, or to...
: (A more in-depth example can be
found here)
(hello.adb)
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is
begin
Put_Line("Hello, world!");
end Hello;
This program can be compiled e.g. by using the freely available open source compiler
GNATGNAT is a free-software compiler for the Ada programming language which forms part of the GNU Compiler Collection. It supports all versions of the language, i.e. Ada 2005, Ada 95 and Ada 83; it allows already some constructs of Ada 2012...
, by executing
gnatmake hello.adb
Data types
Ada's type system is not based on a set of predefined primitive types but allows users to declare their own types. This declaration in turn is not based on the internal representation of the type but on describing the goal which should be achieved. This allows the compiler to determine a suitable memory size for the type, and to check for violations of the type definition at compile time and run time (i.e. range violations, buffer overruns, type consistency, etc.). Ada supports numerical types defined by a range, modulo types, aggregate types (records and arrays), and enumeration types. Access types define a reference to an instance of a specified type; untyped pointers are not permitted.
Special types provided by the language are task types and protected types.
For example a date might be represented as:
type Day_type is range 1 .. 31;
type Month_type is range 1 .. 12;
type Year_type is range 1800 .. 2100;
type Hours is mod 24;
type Weekday is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);
type Date is
record
Day : Day_type;
Month : Month_type;
Year : Year_type;
end record;
Types can have modifiers such as
limited, abstract, private etc. Private types can only be accessed and limited types can only be modified or copied within the scope of the package that defines them.
Ada 95 adds additional features for object-oriented extension of types.
This simple example could be extended to show more features as:
type Working_Hours is range 0..12; -- at most 12 Hours to work a day
subtype Working_Day is Weekday range Monday .. Friday; -- Days to work
Work_Load: constant array(Working_Day) of Working_Hours -- Declaration
:= ( Friday => 6, Monday=>4, others => 10); --lookup table for working hours with initialization
Control structures
Ada is a
structured programmingStructured programming is a programming paradigm aimed on improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures and for and while loops - in contrast to using simple tests and jumps such as the goto statement which could...
language, meaning that the flow of control is structured into standard statements. All standard constructs and deep level early exit are supported so the use of the also supported 'go to' commands is seldom needed.
while a /= b loop
Ada.Text_IO.Put_Line ("Waiting");
end loop;
if a > b then
Ada.Text_IO.Put_Line ("Condition met");
else
Ada.Text_IO.Put_Line ("Condition not met");
end if;
for i in 1 .. 10 loop
Ada.Text_IO.Put ("Iteration: ");
Ada.Text_IO.Put (i);
Ada.Text_IO.Put_Line;
end loop;
loop
a := a + 1;
exit when a = 10;
end loop;
case i is
when 0 => Ada.Text_IO.Put("zero");
when 1 => Ada.Text_IO.Put("one");
when 2 => Ada.Text_IO.Put("two");
-- case statements have to cover all possible cases:
when others => Ada.Text_IO.Put("none of the above");
end case;
with the extension above e.g. Working_Day
for aWeekday in Weekday'Range loop -- loop over an enumeration
Put_Line(Weekday'Image(AWeekday) ); --output string representation of an enumeration
if AWeekday in Working_Day then -- check of a subtype of an enumeration
Put_Line(" to work for" & Working_Hours'Image(Work_Load(aWeekday))); --access into a lookup table
end if;
end loop;
Packages, procedures and functions
Ada programs consist of packages, procedures and functions.
Example:
Package specification (example.ads)
package Example is
type Number is range 1 .. 11;
procedure Print_and_Increment (j: in out Number);
end Example;
package implementation (example.adb)
with Ada.Text_IO;
package body Example is
i : Number := Number'First;
procedure Print_and_Increment (j: in out Number) is
function Next (k: in Number) return Number is
begin
return k + 1;
end Next;
begin
Ada.Text_IO.Put_Line ('The total is: ' & Number'Image(j));
j := Next (j);
end Print_and_Increment;
begin
while i < Number'Last loop
Print_and_Increment (i);
end loop;
end Example;
Packages, procedures and functions can nest to any depth and each can also be the logical outermost block.
Each package, procedure or function can have its own declarations of constants, types, variables, and other procedures, functions and packages, which can be declared in any order.
Concurrency
Ada has language support for task-based concurrency. The fundamental concurrent unit in Ada is a
task which is a built-in limited type. Tasks are specified in two parts - the task declaration defines the task interface (similar to a type declaration), the task body specifies the implementation of the task.
Depending on the implementation, Ada tasks are either mapped to operating system tasks or processes, or are scheduled internally by the Ada runtime.
Tasks can have entries for synchronisation (a form of
synchronous message passingMessage passing in computer science is a form of communication used in parallel computing, object-oriented programming, and interprocess communication. In this model, processes or objects can send and receive messages to other processes...
). Task entries are declared in the task specification. Each task entry can have one or more
accept statements within the task body. If the control flow of the task reaches an accept statement, the task is blocked until the corresponding entry is called by another task (similarly, a calling task is blocked until the called task reaches the corresponding accept statement). Task entries can have parameters similar to procedures, allowing tasks to synchronously exchange data. In conjunction with
select statements it is possible to define
guards on accept statements (similar to Dijkstra's guarded commands).
Ada also offers
protected objects for
mutual exclusionMutual exclusion algorithms are used in concurrent programming to avoid the simultaneous use of a common resource, such as a global variable, by pieces of computer code called critical sections. A critical section is a piece of code in which a process or thread accesses a common resource...
. Protected objects are a
monitor-likeIn concurrent programming, a monitor is an object or module intended to be used safely by more than one thread. The defining characteristic of a monitor is that its methods are executed with mutual exclusion. That is, at each point in time, at most one thread may be executing any of its methods...
construct, but use guards instead of conditional variables for signaling (similar to conditional critical regions). Protected objects combine the data encapsulation and safe mutual exclusion from monitors, and entry guards from conditional critical regions. The main advantage over classical monitors is that conditional variables are not required for signaling, avoiding potential deadlocks due to incorrect locking semantics. Like tasks, the protected object is a built-in limited type, and it also has a declaration part and a body.
A protected object consists of encapsulated private data (which can only be accessed from within the protected object), and procedures, functions and entries which are guaranteed to be mutually exclusive (with the only exception of functions, which are required to be side effect free and can therefore run concurrently with other functions). A task calling a protected object is blocked if another task is currently executing inside the same protected object, and released when this other task leaves the protected object. Blocked tasks are queued on the protected object ordered by time of arrival.
Protected object entries are similar to procedures, but additionally have
guards. If a guard evaluates to false, a calling task is blocked and added to the queue of that entry; now another task can be admitted to the protected object, as no task is currently executing inside the protected object. Guards are re-evaluated whenever a task leaves the protected object, as this is the only time when the evaluation of guards can have changed.
Calls to entries can be
requeued to other entries with the same signature. A task that is requeued is blocked and added to the queue of the target entry; this means that the protected object is released and allows admission of another task.
The
select statement in Ada can be used to implement non-blocking entry calls and accepts, non-deterministic selection of entries (also with guards), time-outs and aborts.
The following example illustrates some concepts of concurrent programming in Ada.
with Ada.Text_IO; use Ada.Text_IO;
procedure Traffic is
type Airplane_ID is range 1..10; -- 10 airplanes (= tasks)
task type Airplane(ID: Airplane_ID); -- task type representing airplanes
type Airplane_Access is access Airplane; -- access type (reference) to Airplane
protected type Runway is -- a protected object - the shared runway
entry Assign_Aircraft(ID: Airplane_ID);
entry Cleared_Runway (ID : Airplane_ID);
entry Wait_For_Clear;
private
Clear: Boolean := True; -- protected private data - generally more than just a flag...
end Runway;
type Runway_Access is access all Runway;
-- the air traffic controller takes requests for takeoff and landing
task type Controller(My_Runway: Runway_Access) is
entry Request_Takeoff (ID: in Airplane_ID; Takeoff: out Runway_Access);
entry Request_Approach(ID: in Airplane_ID; Approach: out Runway_Access);
end Controller;
Runway1 : aliased Runway; -- instantiate a runway
Controller1: Controller(Runway1'Access); -- and a controller to manage it
------ the implementations of the above types ------
protected body Runway is
entry Assign_Aircraft (ID : Airplane_ID)
when Clear is -- the entry guard - tasks are blocked until this is true
begin
Clear := False; Put_Line (Airplane_ID'Image (ID) & " on runway ");
end;
entry Cleared_Runway (ID : Airplane_ID) when not Clear is
begin
Clear := True; Put_Line (Airplane_ID'Image (ID) & " cleared runway ");
end;
entry Wait_For_Clear when Clear is begin
null;
end;
end Runway;
task body Controller is
begin
loop
My_Runway.Wait_For_Clear; -- wait until runway is available
select -- wait for two types of requests
when Request_Approach'count = 0 => -- landings have priority
accept Request_Takeoff (ID : in Airplane_ID; Takeoff : out Runway_Access) do
My_Runway.Assign_Aircraft (ID); -- reserve runway
Takeoff := My_Runway; -- tell airplane which runway
end Request_Takeoff; -- end of the synchronised part
or
accept Request_Approach (ID : in Airplane_ID; Approach : out Runway_Access) do
My_Runway.Assign_Aircraft (ID);
Approach := My_Runway;
end Request_Approach;
or -- terminate if nobody left who could call
terminate;
end select;
end loop;
end;
task body Airplane is
Rwy : Runway_Access;
begin
Controller1.Request_Takeoff (ID, Rwy); -- wait to be cleared for takeoff
Put_Line (Airplane_ID'Image (ID) & " taking off..."); delay 2.0;
Rwy.Cleared_Runway (ID);
delay 5.0; -- fly around a bit...
loop
select -- try to request a runway
Controller1.Request_Approach (ID, Rwy); -- this is a blocking call
exit; -- if call returned we're clear for landing - proceed...
or delay 3.0; -- timeout - if no answer in 3 seconds, do something else
Put_Line (Airplane_ID'Image (ID) & " in holding pattern");
end select;
end loop;
delay 4.0; -- do landing approach...
Put_Line (Airplane_ID'Image (ID) & " touched down!");
Rwy.Cleared_Runway(ID); -- notify runway that we're done here.
end;
New_Airplane: Airplane_Access;
begin
for I in Airplane_ID'Range loop -- create a few airplane tasks
New_Airplane := new Airplane(I); delay 3.0;
end loop;
end Traffic;
Pragmas
A pragma is a compiler directive that convey information to the compiler to allow specific manipulation of compiled output. Certain pragmas are built in to the language while other are implementation-specific.
Examples of common usage of compiler pragmas would be to disable certain features, such as run-time type checking or array subscript boundary checking, or to instruct the compiler to insert object code in lieu of a function call (as C/C++ does with inline functions).
See also
- APSE
APSE standing for Ada Programming Support Environment was a specification for a programming environment to support software development in the Ada programming language. This represented the second stage of the U.S. military Ada project; once the language was implemented, it was felt necessary to...
– a specification for a programming environment to support software development in Ada
- List of programming languages
- SPARK (programming language) – a programming language consisting of a highly restricted subset of the Ada, annotated with meta information describing desired component behavior and individual runtime requirements
- VHDL – a hardware description language originally developed at the behest of the U.S Department of Defense that borrows heavily from Ada in both concepts and syntax
- PL/SQL
PL/SQL is Oracle Corporation's procedural extension language for SQL and the Oracle relational database...
- JOVIAL
JOVIAL is a high-order computer programming language similar to ALGOL, but specialized for the development of embedded systems .JOVIAL is an acronym for "Jules Own Version of the International...
– an earlier U.S Military programming language
- Ravenscar profile
The Ravenscar profile is a subset of the Ada tasking features designed for safety-critical hard real-time computing. It was defined by a separate technical report in Ada 95; it is now part of the Ada 2005 Standard.- Restrictions of the profile:...
- Comparison of programming languages
Programming languages are used for controlling the behavior of a machine . Like natural languages, programming languages conform to rules for syntax and semantics.There are thousands of programming languages and new ones are created every year...
- Straw man proposal
A "straw-man proposal", also known as an Aunt Sally, is a brainstormed simple proposal intended to generate discussion of its disadvantages and to provoke the generation of new and better proposals. Often, a straw man document will be prepared by one or two people prior to kicking off a larger...
International Standards
- ISO/IEC 8652
ISO 8652 is the international standard for the computer programming language Ada....
: Information technology—Programming languages—Ada
- ISO/IEC 15291: Information technology—Programming languages—Ada Semantic Interface Specification (ASIS)
- ISO/IEC 18009: Information technology—Programming languages—Ada: Conformity assessment of a language processor (ACATS)
- IEEE Standard 1003.5b-1996, the POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...
Ada binding
- Ada Language Mapping Specification, the CORBA
Chorba , ciorbă , shurpa , shorpo , or sorpa is one of various kinds of soup or stew found in national cuisines across Middle East...
IDLAn interface description language , or IDL for short, is a specification language used to describe a software component's interface...
to Ada mapping
Rationale
(These documents have been published in various forms including print.)
Books
- Grady Booch
Grady Booch is an American software engineer. Booch is best known for developing the Unified Modeling Language with Ivar Jacobson and James Rumbaugh. Grady is recognized internationally for his innovative work in software architecture, software engineering, and collaborative development environments...
: Software Engineering with Ada, California: The Benjamin/Cummings Publishing Company, Inc., 1987. ISBN 0-8053-0604-8
- Jan Skansholm: Ada 95 From the Beginning, Addison-Wesley, ISBN 0-201-40376-5
- Geoff Gilpin: Ada: A Guided Tour and Tutorial, Prentice hall, ISBN 978-0-13-004045-9
- John Barnes
John Gilbert Presslie Barnes is a British computer scientist best known for his role in developing and publicising the Ada programming language....
: Programming in Ada 2005, Addison-Wesley, ISBN 0-321-34078-7
- John Barnes
John Gilbert Presslie Barnes is a British computer scientist best known for his role in developing and publicising the Ada programming language....
: Programming in Ada plus Language Reference Manual, Addison-Wesley, ISBN 0-201-56539-0
- John Barnes
John Gilbert Presslie Barnes is a British computer scientist best known for his role in developing and publicising the Ada programming language....
: Programming in Ada 95, Addison-Wesley, ISBN 0-201-34293-6
- John Barnes
John Gilbert Presslie Barnes is a British computer scientist best known for his role in developing and publicising the Ada programming language....
: High Integrity Ada: The SPARK Approach, Addison-Wesley, ISBN 0-201-17517-7
- John Barnes
John Gilbert Presslie Barnes is a British computer scientist best known for his role in developing and publicising the Ada programming language....
: High Integrity Software: The SPARK Approach to Safety and Security, Addison-Wesley, ISBN 0-321-13616-0
- John Beidler: Data Structures and Algorithms: An Object-Oriented Approach Using Ada 95, Springer-Verlag, ISBN 0-387-94834-1
- Dean W. Gonzalez
Dean Gonzalez the son of Ivy Gonzalez of Newfoundland, Canada and Carmelo Gonzalez of Puerto Rico. Dean Gonzalez is the co-author of "Introduction to Ada for Programmers" along with Dr. David A...
: Ada Programmer's Handbook, Benjamin-Cummings Publishing Company, ISBN 0-8053-2529-8
- M. Ben-Ari: Ada for Software Engineers, John Wiley & Sons, ISBN 0-471-97912-0
- Norman Cohen
Norman Cohen was an Irish film director and producer, best known for directing a number of feature films based on television comedy programmes during the 1970s, including Till Death Us Do Part and Dad's Army , as well as Spike Milligan's Adolf Hitler: My Part in His Downfall.He was also a...
: Ada as a Second Language, McGraw-Hill Science/Engineering/Math, ISBN 0-07-011607-5
- Alan Burns
Professor Alan Burns FREng FIET FBCS SMIEEE CEng is a professor in the Computer Science Department at the University of York, England. He has been at the University of York since 1990, and held the post of Head of Department from 1999 until 30 June 2006, when he was succeeded by John McDermid.He is...
, Andy WellingsAndy J. Wellings is a professor in the Computer Science department at the University of York in northern England. He works closely with Alan Burns on real-time systems, distributed, concurrent and real-time programming languages....
: Real-Time Systems and Programming Languages. Ada 95, Real-Time Java and Real-Time POSIX., Addison-Wesley, ISBN 0-201-72988-1
- Alan Burns
Professor Alan Burns FREng FIET FBCS SMIEEE CEng is a professor in the Computer Science Department at the University of York, England. He has been at the University of York since 1990, and held the post of Head of Department from 1999 until 30 June 2006, when he was succeeded by John McDermid.He is...
, Andy WellingsAndy J. Wellings is a professor in the Computer Science department at the University of York in northern England. He works closely with Alan Burns on real-time systems, distributed, concurrent and real-time programming languages....
: Concurrency in Ada, Cambridge University Press, ISBN 0-521-62911-X
- Colin Atkinson
Colin Ronald Michael Atkinson CBE - Cricketer, schoolmaster and headmaster of Millfield School....
: Object-Oriented Reuse, Concurrency and Distribution: An Ada-Based Approach, Addison-Wesley, ISBN 0-201-56527-7
- Grady Booch
Grady Booch is an American software engineer. Booch is best known for developing the Unified Modeling Language with Ivar Jacobson and James Rumbaugh. Grady is recognized internationally for his innovative work in software architecture, software engineering, and collaborative development environments...
, Doug Bryan: Software Engineering with Ada, Addison-Wesley, ISBN 0-8053-0608-0
- Daniel Stubbs, Neil W. Webre: Data Structures with Abstract Data Types and Ada, Brooks Cole, ISBN 0-534-14448-9
- Pascal Ledru: Distributed Programming in Ada with Protected Objects, Dissertation.com, ISBN 1-58112-034-6
- Fintan Culwin: Ada, a Developmental Approach, Prentice Hall, ISBN 0-13-264680-3
- John English, Fintan Culwin: Ada 95 the Craft of Object Oriented Programming, Prentice Hall, ISBN 0-13-230350-7
- David A. Wheeler
David A. Wheeler is a computer scientist. He is best known for his work on Open source software/Free-libre software and Computer security.-Open Source Software:...
: Ada 95, Springer-Verlag, ISBN 0-387-94801-5
- David R. Musser, Alexander Stepanov
Alexander Alexandrovich Stepanov is the primary designer and implementer of the C++ Standard Template Library, which he started to develop around 1992 while employed at HP Labs...
: The Ada Generic Library: Linear List Processing Packages, Springer-Verlag, ISBN 0-387-97133-5
- Michael B. Feldman: Software Construction and Data Structures with Ada 95, Addison-Wesley, ISBN 0-201-88795-9
- Simon Johnston: Ada 95 for C and C++ Programmers, Addison-Wesley, ISBN 0-201-40363-3
- Michael B. Feldman, Elliot B. Koffman
Elliot Bruce Koffman is a noted computer scientist and educationist. He is the author of numerous widely-used introductory textbooks for more than 10 different programming languages, including Ada, BASIC, C, C++, FORTRAN, Java, Modula-2, and Pascal...
: Ada 95, Addison-Wesley, ISBN 0-201-36123-X
- Nell Dale, Chip Weems, John McCormick: Programming and Problem Solving with Ada 95, Jones & Bartlett Publishers, ISBN 0-7637-0293-5
- Nell Dale, John McCormick
John McCormick is Jean Monnet Chair of European Union Politics at Indiana University Purdue University Indianapolis , and was department chair from 2001 until 2008. He spent eight years working in the environmental movement before becoming an academic...
: Ada Plus Data Structures: An Object-Oriented Approach, 2nd edition, Jones & Bartlett Publishers, ISBN 0-7637-3794-1
- Bruce C. Krell: Developing With Ada: Life-Cycle Methods, Bantam Dell Pub Group, ISBN 0-553-09102-6
- Judy Bishop: Distributed Ada: Developments and Experiences, Cambridge University Press, ISBN 0-521-39251-9
- Bo Sanden: Software Systems Construction With Examples in Ada, Prentice Hall, ISBN 0-13-030834-X
- Bruce Hillam: Introduction to Abstract Data Types Using Ada, Prentice Hall, ISBN 0-13-045949-6
- David Rudd
David Rudd is an American cinematographer. He has been nominated for 4 Emmy Awards and 1 MTV Award for Cinematography.-Life and career:David Rudd was born in Compton, California...
: Introduction to Software Design and Development With Ada, Brooks Cole, ISBN 0-314-02829-3
- Ian C. Pyle: Developing Safety Systems: A Guide Using Ada, Prentice Hall, ISBN 0-13-204298-3
- Louis Baker: Artificial Intelligence With Ada, McGraw-Hill, ISBN 0-07-003350-1
- Alan Burns
Professor Alan Burns FREng FIET FBCS SMIEEE CEng is a professor in the Computer Science Department at the University of York, England. He has been at the University of York since 1990, and held the post of Head of Department from 1999 until 30 June 2006, when he was succeeded by John McDermid.He is...
, Andy WellingsAndy J. Wellings is a professor in the Computer Science department at the University of York in northern England. He works closely with Alan Burns on real-time systems, distributed, concurrent and real-time programming languages....
: HRT-HOOD: A Structured Design Method for Hard Real-Time Ada Systems, North-Holland, ISBN 0-444-82164-3
- Walter Savitch, Charles Peterson: Ada: An Introduction to the Art and Science of Programming, Benjamin-Cummings Publishing Company, ISBN 0-8053-7070-6
- Mark Allen Weiss: Data Structures and Algorithm Analysis in Ada, Benjamin-Cummings Publishing Company, ISBN 0-8053-9055-3
- Henry Ledgard: ADA: AN INTRODUCTION (Second Edition), Springer-Verlag, ISBN 0-387-90814-5
- Dines Bjørner; Ole N. Oest (eds.): Towards a Formal Description of Ada, London: Springer-Verlag, 1980. ISBN 3-540-10283-3
Archives
External links