The Expressiveness of D

%u user at web.news
Tue Nov 2 06:00:47 PDT 2010


%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.
> 
> ----
> 
> Is D orthogonal? Could it be more orthogonal? 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];
> //  auto c = { return [1: new B,2: new C]; };
> 
>   T!(int,int) e = (1,2);
>   e = T!(3,4);
> 
> // ah - so (1,2) syntax on initialization, T!(1,2) when assigning!
>   T!(int,int) d = T!(1,2);
> 
>   e = d;
> 
> // tuples aren't first class, why?
> //  auto f = { return e; };
> }

I then test this in Scala REPL:

scala> class A; class B extends A; class C extends A
defined class A
defined class B
defined class C

scala> val a = List(new B,new C)
a: List[A] = List(B at 1f18cd5, C at 154f6ff)

scala> val b = Map(1 -> new B, 2 -> new C)
b: scala.collection.immutable.Map[Int,A] = Map((1,B at 14512e), (2,C at 1ddbcb1))

scala> var e = (1,2)
e: (Int, Int) = (1,2)

scala> e = (3,4)
e: (Int, Int) = (3,4)

scala> val d = (1,2)
d: (Int, Int) = (1,2)

scala> e = d
e: (Int, Int) = (1,2)

scala> val f = () => e  
f: () => (Int, Int) = <function0>

scala> f()
res0: (Int, Int) = (1,2)



More information about the Digitalmars-d mailing list