Why I chose D over Ada and Eiffel

qznc qznc at web.de
Thu Aug 22 00:59:52 PDT 2013


On Wednesday, 21 August 2013 at 16:21:47 UTC, Ramon wrote:
> As for generics, let me put it this way:
> In Eiffel generics have been an integral part of the language 
> design from the beginning. In D ways and mechanisms are 
> provided to achieve what quite usually is the goal of generics, 
> namely generic algorithms in way, i.e. by having to write code 
> for an algorithm just once. That might seem to be a minor 
> difference, in particular when looking from a "Huh? I can get 
> it done, so what's the fuss all about, eh?" perspective.
> Of course, there the C and successors worlds proponents are 
> right, this incurs a price (which templates do, too ...) and, 
> yes, in the end, somewhere someone or something must sort the 
> types out anyway (because of the way CPUs work).

There are basically two ways to implement generics. Type erasure 
(Java,Haskell) or template instantiation (C++,D). Instantiation 
provides better performance, but sacrifices error messages 
(fixable?), binary code size, and compilation modularity 
(template implementation must be available for instantiation). 
Type safety is not a problem in either approach.

Longer form: http://beza1e1.tuxen.de/articles/generics.html

An interesting twist would be to use type erasure for reference 
types and instantiation for value types. Another idea could be to 
use instantiation selectively as an optimization and erasure in 
general.

> Another example is data types, concretely integers. Ada offers 
> a nice way do precisely nail down precision/storage. If I want 
> to store days_of_month I can have an integer type holding ints 
> between 1 and 31 (which, due to the way they implemented it can 
> be a PITA). Eiffel gives me something quite similar (in a more 
> elegant way) and additionally a "dumb" INTEGER (32 or 64 bit) 
> and than a gazillion subtypes like "INTEGER_16". That's great 
> because in a quick and dirty script a plain integer (max size 
> of CPU) is good enough and keeps life simple. If I need 
> days_of_month I can very easily have that as int type.

In D you can use structs:

   struct days_of_month {
     int day;
     /* fill in operator overloading etc */
   }


More information about the Digitalmars-d mailing list