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

Walter Bright newshound2 at digitalmars.com
Thu Feb 27 12:56:50 PST 2014


On 2/27/2014 2:19 AM, Timothee Cour wrote:
> * cascade operations: they perform a series of operations on the members of a
> single object:
> foo.bar(1)..baz(3)
> equivalent to:
> foo.bar(1)
> foo.baz(3)

D has ranges and algorithms to conveniently chain operations.


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


> * named constructors

I don't see the point of such over using the factory method idiom.


> * distinguish integer divide (~/) vs divide (/), so that 5/2=2, 5~/2=2

Such are needed so rarely - in C they are done with the modf function, and I've 
never seen modf used in the wild.


> * shorthand function declaration with => (used not just for lambdas)

tomayto, tomahto :-)


> * for (var x in collection) //better syntax than foreach(var;collection)

tomayto, tomahto


> * better syntax for optional positional arguments:
> void fun(int x, [int y, int z=3]){...}
> Thinking of which, this would actually solve a long standing problem in D, that
> of specifying optional parameters AFTER a variadic template:
> void fun(T...)(T args, [string file=__FILE__,int line=__LINE__]){...}

Not sure what that is.


> * export for libraries

What does that mean?


> * async/wait etc

Those are a great idea, and we need to do them at some point.



More information about the Digitalmars-d mailing list