Pretty please: Named arguments
Jonathan M Davis
jmdavisProg at gmx.com
Mon Feb 28 23:55:53 PST 2011
On Monday 28 February 2011 23:24:00 Steven Wawryk wrote:
> On 01/03/11 08:08, Don wrote:
> > 2. It introduces a different syntax for calling a function.
> > foo(4, 5);
> > foo(x: 4, y: 5);
> > They look different, but they do exactly the same thing. I don't like
> > that redundancy.
>
> So, out of consistency, I suppose you must be against foreach,
> scope(exit) and every other kind of lowering?
Except that they actually do something different. All adding the variable names
really do in this case is document the name of the variable that each argument
is tied to and enforce that the names you give are valid. While it does allow
for some increased flexibility in cases where a function takes multiple default
arguments, for the most part it's just documentation. For the most part, it's
not actually doing anything for you. It's not even syntactic sugar.
Now, obviously there are a number of people here who think that this compiler-
verified documentation is worth having, but for the most part, that's all this
is. It's not cutting down on boiler plate code or reducing how much you have to
type to do a particular type of operation (in fact, it's increasing it). So,
this is not at all comparable to foreach or scope or other features which use
lowering to transform code. At most, this results in the re-ordering of
arguments. It's a totally different type of feature.
Really, named arguments are compiler-enforced documentation which allow you to
do a couple of things that you wouldn't be able to do normally (re-order
arguments and give arguments for parameters with default arguments without
giving arguments for parameters earlier in the parameter list which have default
arguments). They're not really anything fancier than that. So, they're not
really comparable to foreach or scope statements. In my opinion (and Don's it
seems), they just don't pull their weight, unlike features such as foreach and
scope statements. We appear to be outnumbered however.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list