Pretty please: Named arguments
Steven Schveighoffer
schveiguy at yahoo.com
Mon Feb 28 12:03:58 PST 2011
On Mon, 28 Feb 2011 14:56:15 -0500, Adam Ruppe <destructionator at gmail.com>
wrote:
>> But then you're back to square one
>
> Obviously, you'd do:
>
> Size size;
> size.width = 10;
> size.height = 20;
>
> Instead of Size(10, 20).
I could also do:
int width = 10, height = 20;
foo(width, height);
The struct solution helps prevent incorrect ordering. But other than
that, it still looks more verbose than should be necessary.
> Another alternative is to give each element their own struct...
>
> struct Width { int width; alias width this; }
>
> foo(Width(10), Height(20));
This seems like extreme overkill. I don't want to have to create a new
struct for every parameter that I want to pass in a named fashion.
Why can't we just pass integers where integers make sense, and give them
names that only exist at compile time? I don't see the harm in the
proposal. Certainly every counter proposal I've seen to be able to
"accomplish the same thing" with today's compiler is worse than just
passing two ints.
-Steve
More information about the Digitalmars-d
mailing list