Skip to content
LumenaryAcademy

Lumenary CS · Programming languages

Ada

The language built for software that must not fail, taught as modern Ada 2012 and Ada 2022: strong types, packages, contracts, tasking and a first look at formal proof with SPARK.

Ada is a compiled, strongly typed language designed for the United States Department of Defense by a team led by Jean Ichbiah. Its first reference manual appeared in 1980, and it became an ANSI standard, Ada 83, in 1983; it has been revised as Ada 95, Ada 2005, Ada 2012 and Ada 2022. It is used where a software failure can cost lives or fortunes: flight-control and avionics software, railway signalling, air-traffic control, satellites and launchers, defence systems and, increasingly, security-critical firmware. Its signature ideas are types that model the problem exactly, packages that hide what should be hidden, contracts that state what code promises, concurrency built into the language, and SPARK, a subset of Ada whose programs can be proved free of whole classes of errors.

This course teaches modern Ada: Ada 2012, with the Ada 2022 features that the GNAT 14 compiler supports, marked as such. It goes from a first program, through types, subprograms, records, arrays and strings, packages and generics, to object orientation with tagged types, contracts, tasks and protected objects, and ends with a complete concurrent project. It assumes the Start level of Lumenary CS or equivalent experience: you know what a variable, a loop and a function are. No previous Ada is needed.

To run the programs you need the GNAT compiler. The Ada community recommends installing it with Alire, Ada's package manager, which downloads a toolchain for Linux, macOS or Windows (see Getting started on ada-lang.io); on Debian and Ubuntu, sudo apt install gnat gprbuild also works. There is no official online playground, but the interactive courses at learn.adacore.com let you edit and run Ada in the browser. Every program in this course was compiled and run with GNAT 14.

AI-draftedAwaiting review by a computer scientist
  • Chloe · The Designer
    “Why is the language built this way?”
  • Margaret · The Profiler
    “What does it print, and what does it cost?”
  • Gideon · The Language Lawyer
    “What exactly does the language guarantee?”

Foundations · 3 lessons

The core language

Where Ada came from and how to compile it, the strong types, ranges and subtypes at its heart, control flow, and procedures and functions with their parameter modes and exceptions.

  1. 1First steps in AdaWhy the US Department of Defense commissioned a language, where Ada flies today, and how a source file becomes a running program. 50 min
  2. 2Strong types and control flowInteger, enumeration, modular and real types with ranges of your choosing, subtypes that narrow them, and Ada's if, case and loop statements. 55 min
  3. 3Procedures, functions and exceptionsSubprograms whose parameters say which way data flows, expression functions and overloading, and exceptions for the things that go wrong. 55 min

Practice · 3 lessons

Data and abstraction

Records, arrays and strings for modelling data, packages and generics for building abstractions that hide their details, and tagged types for object-oriented design.

  1. 4Records, arrays and stringsModelling data with records and discriminants, arrays indexed by anything discrete, slices, and Ada's three kinds of string. 55 min
  2. 5Packages and genericsSpecifications and bodies, private types that protect their own rules, generic units, the standard containers, and how real Ada projects are laid out with Alire. 60 min
  3. 6Tagged types and object orientationType extension, primitive operations, class-wide types and dispatching, interfaces, and controlled types that clean up after themselves. 55 min

Professional · 2 lessons

Ada for high-integrity software

Contracts, predicates and invariants with an overview of SPARK proof, then tasks and protected objects for concurrency, the Alire workflow and a complete project.

  1. 7Contracts, predicates and SPARKPreconditions, postconditions, predicates and type invariants that state what code promises, how to check them, and how SPARK proves them before the program runs. 60 min
  2. 8Tasks, protected objects and a projectConcurrency built into the language, from tasks and rendezvous to protected objects with barriers, then a complete concurrent program and where to go next. 65 min

Further reading and resources