DIP 1019--Named Arguments Lite--Community Review Round 1
Rubn
where at is.this
Sun Feb 17 13:12:11 UTC 2019
On Sunday, 17 February 2019 at 00:27:42 UTC, Yuxuan Shui wrote:
>>> Opt-in: Calling a function with named arguments is opt-in on
>>> the callee side.
>>
>> @named is not the best idea. I don't want to have to check
>> every time if the library author remembered to slap @named on
>> the function I want to use named arguments with. Making it
>> opt-in will probably mean that there will be people who use it
>> and those who don't, and libraries written by users who don't
>> will just cause frustration by those who do; and, for people
>> who do, they might as well just slap it on everything, further
>> contributing to attribute bloat. Also, the decision to use
>> named arguments depends as much on the function as on the call
>> site (e.g. how important is code readability vs. terseness in
>> that particular piece of code). I'd be just too tempted to
>> patch the compiler to enable it for everything.
>
> It's not my favorite either. But I feel it is the best we can do
> at the moment.
I'd say enabling named parameters for everything would be better
than any benefits you get with using an attribute.
@named void foo(int a, int b);
@named void foo(int c, int d);
I don't find the above situation all that useful. There are
multiple ways to deal with this. Using another type for the
parameters:
void foo( Size ab );
void foo( Point cd );
Or simply give the functions a different name to distinguish
between them.
Allowing two functions to exist with the same type signature just
adds unnecessary complexity.
Looking at a few languages that support named parameters they
don't support this kind of named parameters. This includes C# and
Python.
def abc(a, b):
print( "ab", a, b)
def abc(c, d):
print( "cd", c, d)
abc(c=10, d=20)
abc(a=12, b=23) # error the second def of abc() replaces the
first
If you want this functionality you are probably going to have to
make a more concrete case for it than what is currently in the
DIP. If there are any languages that implement it the way you
want to implement it it would probably be a good idea to include
them as examples.
More information about the Digitalmars-d
mailing list