Ada shares many purposes with D: correctness from the language design too, mostly imperative, native compilation, efficiency of the binary, closeness to the metal (even more, because not requiring a GC, it's probably usable in more situations), generic programming, OOP, strong static typing, and both languages share many small features (like array slicing syntax, and so on).

Coding in Ada is a bit boring, because you have to specify every small detail and to write a lot, but for certain programming tasks, like code that can't have too many bugs, it's maybe the best language. As Ada vendors say, if your life depends on a program, you often prefer that code to be written in good Ada instead of good C. Even if writing Ada is slower than writing C or C++, you save some time later debugging less. Today for certain tasks Haskell seems to produce reliable code, but it uses a GC and it's lazy, so it's quite less strict compared to Ada.

I've found another pack of slides about the Ada 2012 language:
http://www.slideshare.net/AdaCore/ada-2012

Come quotations and comments from/about the slides:

[page 3] >In High-Reliable Software, choice is usually being made between C C++ Java Ada<

Maybe someday D too will be among those.


[p.6] >Applying these skills to any programming language should be easy for any developer<

Good luck with programming in Haskell :-)


[p.7] >Is the language properly supported by tools?<

Right, some bugs are avoided thanks to the supporting tools too.


[p.8] >Can the language full development cycle (specification/code/verification)?<

I don't know, regarding D.


[p.15] >Put as much (formal) information as possible in the code<

This is quite important for a language that wants to enforce more correctness.


[p.17] >Values are checked at run-time (can be deactivated)<

This often saves the programmer ass.


[p.19] >Arrays can be indexed by any discrete types (integers, enumeration)<

This is quite handy for enums (and sometimes chars), and reliable. Currently in D if you define an array with enum index you get an associative array, that is wasteful in both memory and performance for most enums that have contiguous values (but I think maybe D implementations will be free to use a more efficient array here, because the interface of AAs is opaque).


[p.21]
Three parameter modes : in (input), out (output) and in-out (input/output)

procedure Do_Something
  (P1 : in     Integer; --  P1 can’t be changed
   P2 : out    Integer; --  No initial value on P2

In D P2 is initialized...


[p.21]
The compiler decides if it has to be passed by reference of copy

procedure Do_Something
  (P1 : in Huge_Structure) –-  Passed by reference if too big

D offers more low-level knowlege/control here, it doesn't decide to pass by value or reference, leaving the decision to the programmer, I prefer D here. But in D code like this, where a large value is passed, I'd like the D compiler to give a warning (despite once in a while that's exactly what you want?):

alias int[1_000] TA;
void int(TA a) {}


[p.22]
Generalized contracts are available through pre and post-conditions

procedure P (V : in out Integer)
   with Pre  => V >= 10,
        Post => V'Old /= V;

So there's the Old (prestate) too in the Ada2012 built-in contract programming.


[p.30]
* Pointers are typed, associated with accessibility checks
* Objects that can be pointed are explicitly identifed
* Pointers constraints can be specified
– Is null value expected?
– Is the pointer constant?
– Is the object pointed by the pointer constant?

Ada has severl kinds of pointers, according to how much freedom they have.


[p.36]
Ada 2012 detects "obvious" aliasing problems

function Change (X, Y : in out Integer) return Integer is
   begin
      X := X * 2;
      Y := Y * 4;

      return X + Y;
   end;

   One, Two : Integer := 1;

begin

   Two := Change (One, One);
-- warning: writable actual for "X" overlaps with actual for "Y“

   Two := Change (One, Two) + Change (One, Two);
-- warning: result may differ if evaluated after other actual in expression

Are such warnings/tests useful in D too?
D compiles this with no warnings/errors:

int change(ref int x, ref int y) {
    x *= 2;
    y *= 4;
    return x + y;
}
void main() {
    int one = 1, two;
    two = change(one, one);
    two = change(one, two) + change(one, two);
}


[p.42]
if C in 'a' | 'e' | 'i'
      | 'o' | 'u' | 'y' then

Sometimes Ada2012 is succint too.


[p.43]
Function implementation can be directly given at specification time if it represents only an "expression"

function Even (V : Integer) return Boolean
   is (V mod 2 = 0);

It's related to:
http://d.puremagic.com/issues/show_bug.cgi?id=7176

Bye,
bearophile

Reply via email to