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

rikki cattermole rikki at cattermole.co.nz
Mon Apr 1 13:21:48 UTC 2019


On 02/04/2019 2:06 AM, bachmeier wrote:
> On Sunday, 31 March 2019 at 12:33:56 UTC, Mike Parker wrote:
>> This is the feedback thread for the first round of Community Review 
>> for DIP 1020, "Named Parameters":
> 
> While I generally do not like the idea of named parameters for function 
> calls, I will limit my feedback here to one part of the proposal:
> 
>> Arguments matching named parameters must be named arguments, i.e. they 
>> must use the name:value syntax. Named arguments must be passed to a 
>> function in the same order as the named parameters with which they 
>> match appear in the parameter list, but may be passed in any order 
>> relative to unnamed arguments. Given the prototype:
>>
>> void func(int a, int b, <bool o>);
>>
>> The function call func(1, 2, o:true) is the same as func(1, o:true, 2) 
>> or func(o:true, 1, 2).
> 
> It is unclear what we would gain from allowing this, and at the same 
> time, it would make it extremely difficult for new users to the language 
> to read code. Reordering unnamed parameters is a recipe for disaster. In 
> some cases, the second argument is x, in some cases it is y, and in yet 
> other cases, it is z. Was there are mistake when writing this:
> 
>> Named arguments must be passed to a function in the same order as the 
>> named parameters with which they match appear in the parameter list, 
>> but may be passed in any order relative to unnamed arguments.
> 
> It makes sense to allow named arguments to appear out of order, but 
> unnamed parameters should always have to appear in the same order as 
> they are declared.

You misunderstood :)

Unnamed arguments must remain in the same order they are declared in.

Named arguments must remain in the same order they are declared in, but 
they may be inserted in between unnamed arguments giving a partial 
reordering.

I.e.

void func(int a, <int b>, int c, <int d>) {}

Valid:

func(1, b: 2, d: 3, 4);

Invalid:

func(1, d: 2, c: 3, 4);

Basically, if you split named and unnamed in the above example you would 
get two sets of parameter lists:

int a, int c
<int b>, <int d>

As long as each parameter list stays in that order, it should be legal 
to be called/initialized.

Does that answer your question/concerns?


More information about the Digitalmars-d mailing list