DIP 1020--Named Parameters--Community Review Round 1

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Apr 17 21:33:42 UTC 2019


On 4/10/19 4:03 PM, Walter Bright wrote:
> On 4/9/2019 12:46 PM, Seb wrote:
>> It allows library authors optionally to control exactly which 
>> parameters are positional and which are keyword-only and which are both.
>>
>> [1] https://www.python.org/dev/peps/pep-0570/
> 
> Note that there is a way to require positional-only in D:
> 
>      int foo(int);
> 
> I.e. leave off the parameter name.
> 
> It works when there's a separate .di file from the implementation .d 
> file (which would have the names). It won't work for template parameters.
> 
> As for renaming parameters,
> 
>      void foo(T oldname);
> 
> becomes:
> 
>      void foo(T)(T oldname) { return foo(newname : oldname); }
>      void foo(T newname);
> 
> Yeah, it's a little awkward, but if you're renaming parameters you've 
> got awkward backwards compatibility issues anyway.

Regarding reordering, here's a nice demo:

https://youtu.be/G5SIwRinEYk?t=994

The presenter has a plot described like this:

line3d(v, color='purple', thickness=3, spin=3)

Then he nicely changes a parameter and the plot gets updated in near 
real-time.

Also note how the call mixes positional with named arguments: the 
important/required one comes first, followed by optional ones. The 
ordering of named parameters does not matter, it's irrelevant whether 
the thickness comes before or after the color etc.

Such usability advantages and concerns need to be front and center in a 
named parameter proposal.


More information about the Digitalmars-d mailing list