Dart and D: features that could be used in D, D->dart for web programming

bearophile bearophileHUGS at lycos.com
Thu Feb 27 14:40:12 PST 2014


Walter Bright:

>> * optional named parameters arguments (with simplest possible 
>> syntax)
> This comes up now and then. The problem with it is it makes 
> function overloading a near impossibility to untangle.

Do you have an example of the problem?


>> * better way to define default constructors:
>> class Point {
>>   num x;
>>   num y;
>>   num z;
>>   // Syntactic sugar for setting z and x before the 
>> constructor body runs.
>>   Point(this.z, this.x){...}
>> }
>> This is more explicit and flexible than D's way for default 
>> struct constructors,
>> which can only allow to set all fields in order, without 
>> skipping some, and
>> doesn't allow to do anything else in the ctor.
>
> D doesn't allow non-trivial default struct constructors for 
> some good reasons, which are a long discussion we've had many 
> times. These reasons don't apply to javascript.

The idea of having some syntax like this is nice, it reduces the 
poilerplace code, making the code less noisy and reducing the 
probability of the currenty common bugs caused by having fields 
and arguments with equal or similar names:

class Foo {
     int x;
     this(this.x) {}
     void inc(int x) { this.x += x; }
}


>> * shorthand function declaration with => (used not just for 
>> lambdas)
>
> tomayto, tomahto :-)

There is an enhancement request on this in Bugzilla.
A shorter syntax for simple functions is handy, because one-line 
functions have become very common in D.

Bye,
bearophile


More information about the Digitalmars-d mailing list