Presentation under the GPL license by Ludovic Brenta: "I originally wrote these slides for a 40-minute "introduction to Ada"
that I gave at the Libre Software Meeting in Bordeaux in 2004. I made
sure these slides were suitable for reuse.
Their purpose is not to teach Ada; this is impossible to do in just 40
minutes. Instead, they try to give an overview of the main features
of Ada and provide pointers to further information."
4. Who uses Ada in 2004?
Space and aeronautics
Eurofighter: 2 million lines of Ada
code
Boeing (in progress: 7E7)
Airbus (in progress: A380,
A400M)
Ariane
Satellites
Eurocontrol (air traffic control)
Their subcontractors: Barco
Avionics, Thales, BAe Systems,
Smiths Aerospace, Raytheon, etc.
5. Qui utilise Ada en 2004?
Rail transport industry
French highspeed train (TGV)
Metro lines in New York, Paris (line 14), Delhi, Calcutta, etc.
Nuclear industry
Electricité de France (EDF): emergency reactor shutdown
Other
Financial: BNP (France), Paranor (Switzerland), PostFinance
Healthcare and medical : JEOL (USA), ReadySoft (France)
Automotive : BMW (Allemagne)
Communications : Canal+ (France)
And lots of free software!
6. Why Ada?
In industry
When human life is at stake
When software just has to work (no excuses accepted)
When you want to know why your software works (certification)
Free software
To develop twice as fast as in C
To produce 90% fewer bugs than in C
To be close to the application domain, and protected against machine
details (highlevel programming)
For software to be portable
For software to be maintainable
7. Philosophy (1)
Cost of software development
Design
Implementation
Debugging
Hence the bright idea: bugs are the problem
8. Philosophy (2)
Effort required to correct a bug
1000
900
800
700
600
500
400
300
200
100
0
Implementati Compilation Testing After delivery
on
Hence the bright idea: find bugs as early as possible!
10. Goals of the language
Reduce development and maintenance costs
Prevent writing bugs if possible
Detect bugs as early as possible, preferably during compilation
Encourage code reuse and team work
Packages with separate interface and implementation
●
Generics (a.k.a. templates)
●
Make maintenance easier
Legibility is paramount; language is “autodocumented”
●
Work well in all situations
In the small: embedded, limited resources, real time, no operating
system
In the large: millions of lines of code, networking, GUIs, etc.
11. The type system
Ada is powerfully and statically typed
Detects most bugs at compile time, before ever testing the program!
The main strength of the language
Programmers can define new types
To reflect the application domain
Number_Of_Apples, Number_Of_Oranges; not just Integer
●
To document the constraints of the problem
To not compare apples to oranges
●
The compiler enforces all constraints
●
12. Scalar types
package Apples_And_Oranges is
type Number_Of_Apples is range 1 .. 20; integer
type Number_Of_Oranges is range 1 .. 40; integer
type Mass is digits 4 range 0.0 .. 4000.0; real
type Colour is (Red, Green, Blue); enumeration
end Apples_And_Oranges;
Scalar types have attributes:
T'First, T'Last : constants
T'Range = T'First .. T'Last (range of permitted values)
T'Pred(X), T'Succ (X) : functions that return the previous or next
value
T'Image (X) : a string representation of X
etc.
14. Arrays have attributes
For any array A:
A'Range is the range of the index
A1 : array (4 .. 8) of Integer;
●
A1'Range = 4 .. 8;
●
A2 : array (Colour) of Integer;
●
A2'Range = Red .. Blue;
●
A'Range (N) is the range of the Nth dimension
A'Length and A'Length (N) yield the number of elements
etc.
15. Records
with Ada.Calendar;
package Records is
type Gender is (Male, Female);
type Person (Sex : Gender) is record
First_Name, Last_Name : String (1 .. 100);
case Sex is
when Male => null;
when Frmale =>
Maiden_Name : String (1 .. 100);
end case;
end record;
end Records;
The record above has an optional discriminant
16. Pointers (access types)
Access types are incompatible with one another
Impossible to mix up different pointers (safety)
The compiler guarantees absence of dangling pointers
Pointers are used only when necessary
Dynamic data structures
OO programming and dynamic binding
with Records; use Records;
procedure Pointers is
type Pointer_To_Element;
type List_Element is record
P : Person;
Next : Pointer_To_Element;
end record;
type Pointer_To_Element is access List_Element;
List_Head : Pointer_To_Element := new List_Element;
begin
List_Head.Next := new List_Element;
end Pointers;
19. Subprograms
Procedures and functions as in Pascal, except:
Parameters are “in”, “out” et “in out”
The programmer says what he wants to do, not how to do it
The compiler chooses between byreference and byvalue
Possible to pass large objects (arrays, records) without explit pointers
Overloaded operators
Default parameter values like in C++
Functions
Also overloaded by their return value
Return value cannot be ignored (no ambiguity = safety)
All parameters are “in”
21. Subprograms in OOP
A method is a subprogram that:
accepts one or more parameters of a tagged type T, or access to T
is declared in the same package as T
procedure Foo (Object : in T); method of type T
No particular syntax; “this” parameter is explicit
Selection of methods (binding) may be:
static: decided at compile time
dynamic: decided at run time (as with C++ virtual methods)
For each tagged type T, there is a type T'Class that
encompasses T and its descendants
procedure Foo (Object : in T'Class); not a method
allows forcing static binding
Like “static methods” in C++
23. Control structures
Loops
Branches
procedure Control_Structures is
separate (Control_Structures)
type Colour is (Red, Green, Blue);
function Foo (I : in Natural) return Colour is
I : Natural := 0;
Result : Colour;
begin
function Foo (I : in Natural)
if I in 1 .. 10 then
return Colour
Result := Red;
is separate;
elsif I in 11 .. 20 then
Result := Green;
Col : Colour := Foo (I);
elsif I in 21 .. 30 then
begin
Result := Blue;
for C in Colour loop
end if;
I := I + 1;
end loop;
case I is
when 1 .. 10 => Result := Red;
while I > 1 loop
when 11 .. 20 => Result := Green;
I := I 1;
when 21 .. 30 => Result := Blue;
end loop;
when others => Result := Red;
all cases must be processed
Named_Loop : loop
end case;
I := I + 1;
return Result;
exit Named_Loop when I = 1000;
end Foo;
I := I + 2;
end loop Named_Loop;
end Control_Structures;
27. Tasking (1)
Part of the language; not in a library
Keywords task, protected, accept, entry, abort, etc.
with Ada.Text_IO; use Ada.Text_IO;
procedure Tasking_Example (Nombre_De_Taches : in Natural) is
task type Background_Task;
task body Background_Task is
begin
delay 1.0; 1 second
Put_Line (“I am in a background task”);
end Background_Task;
type Task_Index is range 1 .. 10;
The_Tasks : array (Task_Index) of Background_Task;
begin
Put_Line (“The main task is starting”);
Put_Line (“The main task is waiting for all background tasks to complete”);
end Tasking_Example;
30. Other features
Representation clauses
Allow safe, lowlevel programming
Separate compilation is part of the language
The compiler guarantees consistency of the final executable
No need for a Makefile
Tasks can rendezvous with each other
Standard interfaces with C, COBOL, FORTRAN
Allows using any C library out there (e.g. GTK+)
Controlled objects (Initialize, Adjust, Finalize)
ASIS (Ada Semantic Interface Specification)
high level API to the compiler
a program can inspect an Ada program parsed by the compiler
an ISO standard
31. Even more functionality
Specialised needs annexes in Ada 95
All of them are implemented by GNAT
Annex C : Systems programming (interrupts, machine code)
Annex D : Realtime systems
Annex E : Distributed systems (remote subprogram call)
Annex F : Information system (decimal number representations)
Annex G : Numerics (complex numbers, bounded performance)
Annex H : Safety and Security (aids to certification)
32. More information?
Web sites :
Ada Information Clearinghouse : http://www.adaic.com
ACT Europe Libre Software : http://libre.acteurope.fr
Ada France : http://www.adafrance.org
News groups
comp.lang.ada, fr.comp.lang.ada
Many free books and tutorials are on line
In English and other languages, including French
Thanks to John English for the tasking examples
Ada 95, The Craft of ObjectOriented Programming
http://www.it.bton.ac.uk/staff/je/adacraft