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

Timothee Cour thelastmammoth at gmail.com
Thu Feb 27 17:05:21 PST 2014


>
>
>
>  * 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.
>

I don't recall this syntax 'Point(this.z, this.x){...}' ever being
discussed; can you please provide a link?

* it avoids the following common bug:

struct Point{int x;int y;}
auto a=Point(1,2,3);
//later on we add a field: struct Point{int x; int a; int y; }
//woops!

* less boilerplate / more DRY / more explicit:

struct Point{
Foo x=32;
Bar y;
Baz z;
this(this.y, this.z){} //instead of this(Bar y, Baz z){this.y=y;this.z=z;}
}


This is arguably a preferable syntax.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140227/6874b24a/attachment.html>


More information about the Digitalmars-d mailing list