Struct Initialization syntax
aliak
something at something.com
Mon Jul 23 17:32:23 UTC 2018
On Monday, 23 July 2018 at 16:57:20 UTC, H. S. Teoh wrote:
> It's true that there's potential conflict with named arguments,
> but IMO it's a mighty bad idea to name ctor parameters in a way
> that conflicts with the struct fields.
After using Swift for a while, I've found this to be the exact
opposite. It is on the contrary very common to name parameters as
you would your members because they are very commonly the most
intuitive names.
struct Point {
int x, int y;
this(x: int, y: int) {}
}
auto p = Point(x: 3, y: 4); // what else would you name them?
Can we just consider that named struct init syntax *is* a
generated named constructor?
If named arguments choose a different syntax then you have no
conflict. If they go with the same (i.e. option 2) then you have
seamless consistency.
Cheers,
- Ali
More information about the Digitalmars-d
mailing list