The Expressiveness of D

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Nov 2 07:48:42 PDT 2010


On 11/2/10 7:53 AM, %u wrote:
> I found a slideshow called 'The Expressiveness of Go' recently. The conclusions are:
>
> * Go is not a small language but it is an expressive and comprehensible one.
>
> * Expressiveness comes from orthogonal composition of constructs.
>
> * Comprehensibility comes from simple constructs that interact in easily understood ways.
>
> * Build a language from simple orthogonal constructs and you have a language that will be easy and productive to use.
>
> * The surprises you discover will be pleasant ones.
>
> ----

The slides fared surprisingly poorly with reddit, though I'm not sure 
what that proves (if anything) :o).

> Is D orthogonal? Could it be more orthogonal?

Orthogonality has been long debated in the PL community. Clearly in 
reasonable quantities it's a desirable trait, but one must also know 
where to stop. There are many orthogonal languages that people didn't 
quite enjoy. The most orthogonal of all is Algol, but next to no one 
could bring themselves to actually use it.

Humans are not orthogonal, our linguistic and related abilities don't 
thrive on orthogonality, so it's a tenuous case that orthogonality must 
be a be-all end-all of programming languages.

> Two things come to my mind: removing special cases and making widely used things first class. For data types this means that they have literals, can be given to functions and returned from functions. I made a small test and found that the discoveries aren't pleasant to me:
>
>
> class A {}
> class B : A {}
> class C : A {}
>
> template T(A...) { alias A T; }
>
> void main() {
>    auto a = true ? new B : new C;
> // these don't work - why?
> //  auto b = [new B, new C];

Compiler bug. Must deduce common type as A.

> //  auto c = { return [1: new B,2: new C]; };

Compiler bug again.

>    T!(int,int) e = (1,2);
>    e = T!(3,4);

Variadic alias tuples (incorrectly called type tuples) are one of the 
more awkward features of the language. Though I agree they should 
ideally be made more palatable, I suggest using Tuple instead:

auto e = tuple(1, 2);
e = tuple(3, 4);

> // ah - so (1,2) syntax on initialization, T!(1,2) when assigning!
>    T!(int,int) d = T!(1,2);

auto d = tuple(1, 2);

>    e = d;
>
> // tuples aren't first class, why?
> //  auto f = { return e; };
> }

This should work with the library tuples.


Andrei


More information about the Digitalmars-d mailing list