shorter alternative of constructor with parameter

via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 29 14:37:27 PDT 2014


On Monday, 23 June 2014 at 18:20:33 UTC, bearophile wrote:
> I don't think a template/mixin can replace that sufficiently 
> well, because you also often want to put some code inside the 
> constructor.

And it is unreadable. "this.x" is very useful for creating new 
classes in Dart when you build up the main structure of your 
program.

I don't think "this.x" should be considered syntactical sugar. 
That seems semantically like a wrong conclusion. You just specify 
the aggregate variable directly instead of going by a temporary.

Is "a=b" syntactical sugar for "tmp = b; a = b"? No.

Ola.


More information about the Digitalmars-d mailing list