shorter alternative of constructor with parameter

Shammah Chancellor via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 22 04:52:11 PDT 2014


On 2014-06-21 17:17:56 +0000, Suliman said:

> 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 can't support this proposal.   Adds more syntax to a language that is 
already becoming cramped.  I also don't see the purpose of having 
simple constructors like this?  Are you going to add (n choose k) 
simple constructors to a class?   I could get behind field initializer 
syntax ala C# "with" modeling the syntax we have for structures.

new Person() {name: "Bob"};

-Shammah



More information about the Digitalmars-d mailing list