Why I chose D over Ada and Eiffel
bearophile
bearophileHUGS at lycos.com
Sun Aug 25 08:06:27 PDT 2013
Ramon:
> One obious (or seemingly obvious) solution was Ada. Well, no,
> it wasn't. Maybe, even probably, if I had to develop low level
> stuff for embedded stuff but not for a large application. And,
> that was a killer for me, Ada does not really support easily
> resizable arrays. To make things worse, while there nowadays is
> Gnat, a nice modern IDE, there is a major lack of libraries.
>
> Falling over the famous Ariane 5 article
The Ariane 5 failure shows that Ada programs are not
perfect/infallible. But that's true for most languages :-)
Despite Ada has several problems and flaws, it still has some
advantages over D. This is one of the hundreds of RosettaCode
tasks written in Ada:
http://rosettacode.org/wiki/Universal_Turing_machine#Ada
If you compare that Ada version with my laboriously written D
entry (and you can perform a similar comparison with several
other tasks in that site) you see how the D entry replaces tons
of tests done statically by the Ada program with run-time tests,
like:
this(const ref TuringMachine tm_) {
immutable errMsg = "Invalid input.";
enforce(!tm_.runningStates.empty, errMsg);
enforce(!tm_.haltStates.empty, errMsg);
enforce(!tm_.symbols.empty, errMsg);
enforce(tm_.rules.length, errMsg);
enforce(tm_.runningStates.canFind(tm_.initialState), errMsg);
enforce(tm_.symbols.canFind(tm_.blank), errMsg);
const allStates = tm_.runningStates ~ tm_.haltStates;
foreach (const s; tm_.rules.keys.to!(dchar[])().sort())
enforce(tm_.runningStates.canFind(s), errMsg);
foreach (const aa; tm_.rules.byValue)
foreach (/*const*/ s, const rule; aa) {
enforce(tm_.symbols.canFind(s), errMsg);
enforce(tm_.symbols.canFind(rule.toWrite), errMsg);
enforce(allStates.canFind(rule.nextState), errMsg);
}
Despite those tests done by the Ada entry are semantically
simple, they are numerous and good, and I have used a lot of
energy to write the most statically safe D entry. Probably
working even more you can make the D entry a bit more statically
safe (eventually you could reach the level of Ada code) but the
amount of work and code becomes excessive, and the resulting D
code becomes unnatural, and rather not idiomatic.
On this Ada is still a winner :-)
Bye,
bearophile
More information about the Digitalmars-d
mailing list