DIP 1019--Named Arguments Lite--Community Review Round 1
Rubn
where at is.this
Sun Feb 17 17:58:56 UTC 2019
On Sunday, 17 February 2019 at 17:09:57 UTC, Yuxuan Shui wrote:
> On Sunday, 17 February 2019 at 13:12:11 UTC, Rubn wrote:
>>
>> 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.
>
> This is allowed, _right now_. This is not an addition made by
> this DIP. Example: https://d.godbolt.org/z/hbwsaU
Yes that's very different from what you want to implement it. See
below.
>> 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
>
> And they have the problem that the name of the parameter
> becomes part of the API. This is something this DIP tries to
> solve.
>
>>
>> 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.
>
> I am pretty sure this DIP listed some major languages with this
> feature, and it also includes concrete examples.
Yes and Python doesn't behave the way you are suggesting. Listing
the languages that implement the feature but not how they
implement it makes the argument weaker. You list Python but I
would not say Python implements this feature the same way as you
are suggesting it to be implemented. I'd use Python as an example
against this DIP (as I have).
Eg the DIP suggests this be valid code so long as it can be
distinguished by at least one parameter.
@named:
int add(int a, int b) { ... }
int add(int c, int d) { ... }
If you try and do the following currently:
int add(int a, int b) { ... }
int add(int c, int d) { ... } // error
You get a compiler error. Defining two functions with the same
type signatures shouldn't be possible, with or without named
parameters. It just adds un-needed complexity.
More information about the Digitalmars-d
mailing list