Nicer syntax for constructors
12345swordy
alexanderheistermann at gmail.com
Sun Nov 18 19:25:09 UTC 2018
On Sunday, 18 November 2018 at 19:09:16 UTC, Trailzz wrote:
> This situation happens *very* often in object oriented
> programming:
> ```
> this(string a, int b, char c, float d, uint e, bool f)
> {
> this.a = a;
> this.b = b;
> this.c = c;
> this.d = d;
> this.e = e;
> this.f = f;
> }
> ```
>
> It would save a lot of code bloat if there was a simpler syntax
> for this, perhaps something like this:
> ```
> this(string this.a, int this.b, char this.c, float this.d, uint
> this.e, bool this.f)
> {
> }
> ```
>
> It would be very easy to infer the types here, so this could
> also work
> ```
> this(this.a, this.b, this.c, this.d, this.e, this.f)
> {
> }
> ```
>
> I'm not sure exactly what the syntax would be like, but I just
> wanted to know what other people think about this. Would it be
> worth creating a DIP for this?
Have tried to use templates/string mixin for this? Don't rush to
a DIP yet, until you exhaust other options.
More information about the Digitalmars-d
mailing list