Ada Tutorial
Learn Ada step by step: 36 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Ada? History, Goals and Where It Is Used Meet Ada, the language built for software that must not fail: its history, design goals, how it differs from C, where it flies and rides, and how this course works.
- Hello World and the Structure of an Ada Program Write your first Ada program and learn its structure: context clauses with and use, the declarative part, begin and end, comments, identifiers and the layout rules.
- GNAT, gprbuild and the Ada Toolchain Set up a real Ada toolchain: GNAT, gprbuild project files, Alire, file naming rules, compiler switches and the compile-bind-link steps that turn Ada source into programs.
- Variables, Constants and Declarations in Ada Declare variables, constants and named numbers in Ada, learn initialization, the := assignment, declare blocks, scope and why Ada makes you name a type for everything.
- Text_IO: Reading and Writing Text in Ada Learn Ada.Text_IO and the generic packages for integers and floats: Put, Put_Line, Get, Get_Line, formatting with Width, 'Image, files and the standard streams.
Types and Control Flow
- Integer and Floating-Point Types in Ada Define your own numeric types in Ada with range constraints, modular types, subtypes, floating-point digits and fixed-point deltas, and see how overflow is caught.
- Enumerations, Characters and Booleans in Ada Learn Ada enumeration types and the attributes Pos, Val, Succ, Pred, Image and Value, how Boolean and Character are enumerations, and how to use them as loop and array indexes.
- Arrays and Strings in Ada: Bounds, Slices and Attributes Master Ada arrays: any discrete index range, constrained and unconstrained types, slices, aggregates, the attributes First, Last, Range and Length, and why String is just an array.
- Records, Discriminants and Aggregates in Ada Group data with Ada records: components, default values, aggregates with named association, discriminants, variant records and how they compare with C structs and unions.
- If, Case and Loops: Ada Control Flow Control the flow of an Ada program with if and elsif, exhaustive case statements, for and while loops, bare loops with exit, loop labels, quantified expressions and goto.
Subprograms and Packages
- Procedures, Functions and Parameter Modes in Ada Write Ada subprograms: procedures versus functions, the parameter modes in, out and in out, default and named parameters, expression functions and how Ada passes arguments safely.
- Packages in Ada: Specification and Body Organize Ada code into packages: the specification as the public contract, the body as the hidden implementation, initialization, package state, use clauses, renaming and the Ada standard library.
- Private Types, Limited Types and Child Packages in Ada Hide representation in Ada with private and limited private types, understand opaque handles, build hierarchies with child packages and private children, and keep invariants safe.
- Overloading, Nested Subprograms and Recursion in Ada Use Ada features that shape larger programs: overloading subprograms and operators, user-defined operators, nested subprograms with access to outer variables, forward declarations and recursion.
Strong Typing and Generics
- Derived Types and Strong Typing in Ada See how Ada prevents unit mix-ups with derived types, explicit conversions, subtype predicates and dimensional types, with the famous Mars Climate Orbiter failure as motivation.
- Access Types, Dynamic Memory and Linked Lists in Ada Learn Ada pointers (access types): allocating with new, null, dereferencing, storage pools, Unchecked_Deallocation, linked structures, access to subprograms and safer alternatives like containers.
- Generics in Ada: Reusable Packages and Subprograms Write reusable Ada code with generic subprograms and packages, formal type, object and subprogram parameters, instantiation, the standard containers and the difference from C++ templates.
- Tagged Types and Object-Oriented Programming in Ada Do object-oriented programming in Ada with tagged types: extension, primitive operations, overriding, class-wide types and dynamic dispatch, abstract types, interfaces and the dot notation.
Tasking and Concurrency
- Tasks and Task Types Learn how Ada builds concurrency into the language: task declarations, task types, discriminants, activation, termination and master scopes, with runnable C stand-ins.
- Rendezvous and Entries Understand Ada's rendezvous: task entries, accept statements, entry parameters, queues and synchronous hand-offs between tasks, with a runnable C stand-in.
- Protected Objects Protected objects give Ada tasks safe shared data: functions, procedures and entries with barriers, mutual exclusion without explicit locks, plus runnable C stand-ins.
- Select, Delay and Termination Learn Ada's selective accept: select with several accepts, guards, delay alternatives, the terminate alternative, abort and priorities, with runnable C stand-ins.
Exceptions and Contracts
- Exceptions in Ada Learn Ada exceptions: predefined ones like Constraint_Error, declaring your own, raise, exception handlers, re-raising and exception messages, with C stand-ins.
- Propagation, Cleanup and Finalization How Ada exceptions propagate through subprograms, tasks and declarations, how to release resources safely, and how Controlled types finalize objects, with C stand-ins.
- Preconditions and Postconditions Use Ada 2012 contracts: Pre and Post aspects, the 'Result and 'Old attributes, Contract_Cases, assertion policy and how contracts differ from exceptions, with C stand-ins.
- Type Invariants and Predicates Learn Ada type contracts: Static_Predicate, Dynamic_Predicate and Type_Invariant aspects that keep data valid, when they are checked and how they differ, with C stand-ins.
SPARK and Safety
- What Is SPARK? SPARK is a verifiable subset of Ada. Learn what it restricts, what GNATprove proves, the SPARK_Mode aspect, assurance levels and where SPARK is used, with C stand-ins.
- Flow Analysis and Data Dependencies Learn SPARK flow analysis: the Global, Depends and Initializes aspects, detecting uninitialized variables, ineffective statements and information leaks, with C stand-ins.
- Proving Absence of Run-Time Errors Prove that Ada code never overflows or indexes out of range with SPARK: run-time check obligations, loop invariants, assertions, ghost code and how to read unproved checks.
Systems and Tools
- Representation Clauses and Bit Layout Control data layout in Ada: Size and Alignment, enumeration representation, record representation clauses, bit-order and modular types for hardware registers, with C stand-ins.
- Interfacing with C Call C from Ada and Ada from C: pragma Import, Export, Convention, Interfaces.C types, strings, callbacks and pointers, with runnable C stand-ins for the C side.
- GNAT, GPRbuild and Alire A tour of the Ada toolchain: the GNAT compiler, gprbuild project files, the Alire package manager, style and warning switches, GNATprove, GNATtest and GNATcoverage.
- Embedded and Low-Level Ada Ada on microcontrollers: memory-mapped registers with address clauses, Volatile, interrupt handlers in protected objects, the Ravenscar profile, restrictions and run-times.
Projects and Practice
- Project: Bounded Ring Buffer Build a bounded ring buffer in Ada with a protected type, barriers, contracts and a producer/consumer pair, plus a runnable C model with threads to test the design.
- Project: Traffic Light State Machine Design a safe traffic light controller in Ada: enumeration states, a transition function with contracts, a periodic task and safety properties, with a runnable C simulation.
- Practice: Ada Concepts Review Review tasking, exceptions, contracts, SPARK and systems programming in Ada with a mixed set of questions, worked exercises with answers and runnable C practice programs.