Ada

Ada was designed in the late 1970s for the US Department of Defense and named after Ada Lovelace. It is structured like Pascal but goes much further in making mistakes impossible or loud. It is used where a bug can cost lives: avionics, railways, space and medical devices.

Paradigm: Structured Programming

What Makes Ada Special

  • Types describe real ranges. You declare type Percent is range 0 .. 100;, and the compiler and runtime enforce it. Values never silently leave their range.
  • Checks are on by default. Range, index and overflow checks raise exceptions instead of corrupting memory. SPARK, a subset of Ada, even proves their absence.
  • Readable, verbose syntax. Keywords such as is, begin and end loop favor reading over typing. Code is read far more often than written.
  • Packages and generics. Programs are split into specification and body files, so interfaces are separate from implementations. Generic units allow reuse.
  • Concurrency is built in. Tasks and protected objects are language features, not library add-ons, which suits real-time embedded systems.

Example: A range that cannot be exceeded

with Ada.Text_IO; use Ada.Text_IO;

procedure Checked_Range is
   type Percent is range 0 .. 100;
   Score : Percent := 95;
begin
   for Bonus in 1 .. 10 loop
      Score := Score + 1;
      Put_Line ("Score:" & Percent'Image (Score));
   end loop;
exception
   when Constraint_Error =>
      Put_Line ("Score can never leave 0 .. 100");
end Checked_Range;

How It Works

  • Percent is a distinct type, not just an Integer: it cannot be mixed with other numeric types without an explicit conversion.
  • The loop adds one to the score each time and prints 96, 97, 98, 99 and 100.
  • On the sixth iteration the value would become 101. Instead of wrapping around, the runtime raises Constraint_Error.
  • The exception section handles the error and prints a message. The rule was stated once, in the type declaration.

History and Where It Is Used

Ada is used in avionics (Boeing 777 and Airbus systems), air traffic control, railway signalling, satellites and defense. The GNAT compiler is free, and AdaCore's SPARK toolset supports formal verification. Recent interest in memory-safe languages has brought Ada new attention, and Oracle PL/SQL borrows its syntax from Ada (see the PL/SQL roadmap). See the Ada roadmap for a complete course.

Learn More