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

Paul Backus snarwin at gmail.com
Fri Feb 15 20:28:02 UTC 2019


On Friday, 15 February 2019 at 18:32:52 UTC, Yuxuan Shui wrote:
>> 5. Similarly, as already mentioned by somebody else, the DIP 
>> fails to explain interaction with function default arguments.
>
> I think it is reasonable to require a prefix of the parameters 
> are specified.
>
> e.g. int fun(int a, int b = 1, int c = 2, int d = 3);
>
> The user can specify (a), (a, b), (a, b, c) or all of the 
> parameters, and the arguments can be in any order.

In my experience, one of the greatest benefits of argument 
re-ordering is that it lets you leave out optional arguments at 
the call site. For example, in Python, if you wanted to use the 
default value for every argument except `d`, you could write this:

     fun(a=123, d=456)

...whereas with this proposal, you'd be required to needlessly 
repeat the default values for `a` and `b`:

     fun(a: 123, d: 456, b: 1, c: 2);

If this DIP isn't going to allow leaving out optional arguments 
in all cases, it might be better to simply forbid argument 
re-ordering entirely (or at least, to leave the issue for a 
future DIP).


More information about the Digitalmars-d mailing list