Pretty please: Named arguments
Don
nospam at nospam.com
Mon Feb 28 13:38:34 PST 2011
spir wrote:
> On 02/28/2011 07:51 PM, Jonathan M Davis wrote:
>> I'm not entirely against named arguments being in D, however I do
>> think that any
>> functions that actually need them should be refactored anyway.
I agree.
CreateFont() in the Windows API, I'm looking at you. (For Linux people,
that function has about 12 parameters).
> ???
>
>> In actuality, if I were to vote on whether named arguments should be
>> in the
>> language, I would definitely vote against it (I just plain don't want
>> the code
>> clutter, [...]
>
> Just don't use them!
You don't have that option. At least, if you're a library developer, you
don't. (I'm a bit sick of people saying "you don't have to use it if you
don't want to" in language design. If it is in the language, you don't
have a choice. You will encounter it).
There are a couple of things that I really, really don't like about the
names argument idea:
1. It makes parameter names part of the API.
Providing no way for the function writer to control whether it is part
of the API or not, and especially, doing it retrospectively, strikes me
as extremely rude.
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.
Especially since, as far as I can tell, the named arguments are just
comments (which the compiler can check).
If so, a syntax like this would be possible, with no language change at all:
pragma(namedarguments); // applies to whole module
foo(/*x*/ 4, /*y*/ 5);
---> if a function parameter has a comment which forms a valid
identifier, it's a named parameter.
But I still don't see the need for this feature. Aren't people using
IDEs where the function signature (with parameter names) pops up when
you're entering the function, and when you move the mouse over the
function call?
And if you really want to see them all the time, why not build that
feature into the IDE?
("hit ctrl-f9 to show all parameter names, hit it again to hide them").
More information about the Digitalmars-d
mailing list