Why I chose D over Ada and Eiffel

Timon Gehr timon.gehr at gmx.ch
Tue Aug 20 12:47:59 PDT 2013


On 08/20/2013 06:40 PM, Ramon wrote:
> Yes and no.
> While UTF-8 almost always is the most memory efficient representation of
> anything beyond ASCII it does have a property that can be troublesome a
> times, the difference between length and size of a string, i.e. the
> number of "characters" vs. the number of bytes used.
>
> ---
>
> As for another issue I'm getting more and more disappointed: generics.
>
> To put (my mind) bluntly, D does *not* support generics but rather went
> into the same ugly trap C++ went into, albeit D handles the situation
> way more elegantly.
> ...

Yup. It is a limited, but quite well-integrated macro system.

> Forgive me seeming harsh here but I just wrote it in the D gui thread:
> Any really great solution needs a solid philosophy and very profound
> thinking and consistency - and here D failed bluntly (in my minds eye).
> ...

Agreed. Well, it is fixable. The main issue is that templates manage to 
hide the problem well enough. Also, why stop there? The lambda cube has 
more dimensions, and those cannot be approximated that well by templates. :)

> With all due respect: Templates are an editors job, not a compilers.

Here I'd tend to disagree. Code duplication is the compiler's job.

> Yes, templates offer some gadgets beyond simple replacement but
> basically they are just a comfort thingy, relieving the programmer from
> typing.
> ...

Well, but by a similar line of though I might claim that a polymorphic 
type system is just a comfort thingy, relieving the programmer from 
manually boxing and unboxing values and performing type 
equality/constraint checking in his head.

> That, however, was *not* the point about generics. They are about
> implementing algorithms independent of data types (as far as possible).
> ...

This is one use case for templates and they allow more performance 
optimizations since they can actually treat some types specially.

> Now, I'm looking around at mixins and interfaces in order to somehow
> makeshift some kind of a halfway reasonable generics mechanism. Yuck!
>
> Well, maybe it's my fault. Maybe I was foolish to hope for something
> like Eiffel but more pragmatically useful and useable, more C style and
> way better documented. What I seem to have found with D is a *very nice*
> and *way better* and considerably more useful kind of C++.
>
> Why aren't real generics there? I mean it's not that high tech  or hard
> to implement (leaving aside macho bla bla like "It'd break the ranges
> system").
> ...

It wouldn't break the ranges system.
The official justification for lack of a more expressive type system is 
language complexity.

> why not something like
>
> generic min(T:comparable) { // works only with comparable types/classes
>    // min magic
> }
> ...

Implicit parameters would be a more general way to deal with the 
'comparable' constraint, but it's not entirely trivial to dream up a 
pretty scheme fitting into D.

Also, how do you implement the type comparison constraint? Requiring the 
whole interface to be implemented within an struct/class-type's scope 
implies that somewhat ugly wrapper types need to be created.

Also, you really want shortcut syntax for functions, structs etc. that 
does not clash with template syntax, so probably you'd use a separate 
kind of brackets:

T min[T:comparable](T a, T b) { return a<b?a:b; }

> This could then at *run time* work with anything that met the spec for
> "comparable" which basically came down to anything that offers "equ" and
> "gt" (and "not").
> ...

The D term is opCmp.

> On a sidenote: It seems we are somehow trapped in between two worlds,
> the theoreticians and the pragmatics. Walter and his colleagues have
> created an astonishingly beautiful beast coming from pure pragmatic
> engineering, while e.g. Prof. Meyer has created a brilliant system that
> just happens to be factually unuseable for the majority of developers
> (and be it only because hardly anyone will spend some 1.000$ to get
> started with Eiffel).
> ...

One thing that should be noted about Eiffel is that its type system is 
unsound by design.

> It's as if one side a purely as engineers while the other side just
> didn't care sh*t about their stuff being useable and useful.
>
> My sincere apologies if I happened to offend anyone; that was definitely
> not my intention.

You are usually free to express your opinions on here without anyone 
taking issue if you justify your statements and/or are open to discussion.



More information about the Digitalmars-d mailing list