An Introduction to Ada for Beginning and Experienced Programmers (Jean-Pierre Rosen)[FOSDEM 2020]

An Introduction to Ada for Beginning and Experienced Programmers

There’s this joke that you don’t hear about Ada because you don’t have the necessary security clearance to hear about Ada. So this talk should lift the curtain a bit and show us what Ada is all about.

Jean-Pierre immediately opens with a list of several features present in Ada and when they were introduced into the language. It seems that Ada takes pride in being first in implementing a lot of features, especially w.r.t. safety long before the were introduced in more mainstream languages.

There are many different compilers available, both proprietary and free. GNAT is specifically mentioned as the Ada front-end for GCC and is probably the best place for someone to start looking into Ada.

With regards to the popularity of Ada on the TIOBE index, this is explained by the fact that a lot of the software written in Ada is not publicly available and not publicly discussed. Specific examples given of places where Ada is used are:

  • The air traffic control system Eurocontrol uses
  • The Ariane rocket family
  • The TGV
  • The Airbus A380
  • Automated subway systems
  • The Rosetta space probe

With these examples Rosen wants to drive the point home that Ada is very much an industrial language.

The main feature for which to choose Ada is not for what it allows, but for what it disallows. It is recommended for situations where failure is not an option. The specific example of buffer overflows, the main cause for security breaches, is mentioned as being impossible to do in Ada as the compiler detects these and the code does not compile.

Then the discussion moved on to the language itself. It’s syntax is based on Pascal, with modifications that focus on readability. It is a strongly typed language.

The typing system is the foundation of the language.

Other features mentioned as the pillars that support the Ada language are:

  • packages: Packages provide support for OOP in that they have functionality comparable to classes but also modules (from a C++ perspective).
  • Exceptions: Everything bad that can happen will be translated into an Exception. Even violations in C code (i.e. segfaults) will be translated into Ada exceptions. This seems to not be as controversial as in C++ where exceptions are often disabled. The rule is “Once you have taken care of the unexpected, take care of the unexpected unexpected.”
  • Generics: Instantiating of a subprogram in terms of types that are not defined until the user instantiates them, much like C++ templates.
  • Tasking: The language has built-in threading support.
  • Low level programming: The language can talk directly to the hardware. You can describe a record bit-by-bit and the compiler will take care of the implementation.

These support the programming methodology. Ada is designed for a design methodology. The philosophy is that the language should directly support the chosen design methodology. Design errors translate into design error.

The building block approach of Ada

Class is not a keyword even though it is an object oriented language. Instead there is the building block approach. The analogy is made between Playmobil and Lego. Playmmobil is prebuilt, decisions are made for you. A single lego brick is not fun to play with, but combine them together and the possibilities become endless. Ada is the same as the Lego where you combine small blocks into anything you want.

Loop control. The loop object is considered constant by default and it’s scope is limited to the loop. A loop can be named. if it’s named you have to explicitly end it. The compiler checks this. In other languages this is often done with a comment for which you have no guarantee that it is correct.

A switch case will check that every possible value is handled by a case statement. This is mandated by the compiler. If you change a type the compiler will warn you about all the places you need to modify.

Ada has a strong typing system. A type abstracts a real world object. It does not make sense to add the age of a person to the number of floors in a building. Mixing them up will not compile.

type Age is  range 0..125;
type Floor is range -5..15;

My_Age: age
My_Floor: Floor

My_Age := My_Floor; -- FORBIDDEN!

You describe the types at the problem level, the compiler selects the machine implementation.

Another interesting feature is that an interface can be specified and written against before the implementation is actually done. This allows you to discover issues with what is required before you actually start implementing the behaviour.

Object oriented programming.

Tagged types are part of the OOP implementation in Ada. A tagged type supports dynamic binding and thus polymorphism. Combined with the data-hiding of packages this provides OOP functionality.

package Widget is
  type Instance is tagged private;
  procedure Paint (Self: Instance);
  ...
private
  ...
end Widget;

In Ada OOP is implemented without the need for pointers. There is a difference between specific type from class wide type (A widget is not widget’class). You can specify whether you allow sub-classes.

Jean-Pierre Rosen closes his talk by asking us not to use Ada, but to at least give it a try as it is a robust language with lots of interesting features.