If Ada is already *very* safe, why Rust?

You've got to love it when people who nothing about Ada like to tell other people, who know nothing about Ada, things about Ada that they probably heard from someone else, who knew nothing about Ada.

Ada has a new and it has a "free" but free is considered unsafe and is a generic function called Unchecked_Deallocation, because it's unchecked by the compiler.

You would generally wrap your memory allocations within a package inside the private parts either in functions to call from outside the package or using a controlled type, which is a tagged type (or class in other languages) which have Initialize, Adjust and Finalize functions defined which you need to override. Handle your free within Finalize and you essentially have RAII (in other languages). Object goes out of scope and Finalize is called.

Also, there are provisions within the RM which states that when an access type (pointer type) goes out of scope, i.e. from a block, the block master can automatically delete that memory for you. This thread goes into more detail (I cannot put the link in):

Specify the 'Storage_Size associated with the access-type.
The implementation is required to reclaim the storage for the
access type when exiting its scope if a 'Storage_Size is specified
(see RM95 13.11(18)).

One of Ada's best features are ranges, along with array indices:

type Celcius is range -100 .. 100;

type Celcius_Arrays is array (Ceclius'Range) of Integer; -- Example.
...
C : Celcius_Arrays := <some_initialiser>;
...
for C in C'Range loop - Yes, an array from -100 -> 100
  -- Do something
end loop;

[As I cannot post another reply...]

There are no compilers ever written for Ada which implemented the provision for GC.

Not quite true, see my previous post.

type A is access T; -- Can point to local types.
type B is access all T; -- Can point to types on the heap and locally.
type C is not null access T; -- Exclude nulls.
type D is access constant T; -- Can only point to constants.
type D is not null access constant T; -- Can only point to constants and not null.

Then there are access to (protected) functions/procedures, etc.

It's a hell of a lot safer than a lot of other languages out there including C++, which doesn't do the job better.

7 Likes