shorter alternative of constructor with parameter
AsmMan via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jun 23 20:19:56 PDT 2014
On Saturday, 21 June 2014 at 17:17:57 UTC, Suliman wrote:
> Dart and few others modern languages support short declaration
> constructor with parameter:
>
> class Person {
> String name;
>
> Person(String name) {
> this.name = name;
> }
> }
>
> // Shorter alternative
> class Person {
> String name;
>
> // parameters prefixed by 'this.' will assign to
> // instance variables automatically
> Person(this.name);
> }
>
> it's there any DIP for adding this future to D?
I don't agree with this feature. It's ugly. At first look at you
have no idea what it does mean (even if you know have already
some base about programming languages).
I think this type of feature would lead D to became a type of C++.
See C++ foo(int x) : x(x) {} is just too ugly either. I don't
know if there are someone that share same feel.
More information about the Digitalmars-d
mailing list