DIP 1019--Named Arguments Lite--Community Review Round 1

Yuxuan Shui yshuiv7 at gmail.com
Sun Feb 17 17:09:57 UTC 2019


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

>
> 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.


More information about the Digitalmars-d mailing list