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

bachmeier no at spam.net
Mon Apr 1 19:41:25 UTC 2019


On Monday, 1 April 2019 at 13:21:48 UTC, rikki cattermole wrote:

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

That's the part that is going to cause major trouble for someone 
new to the language.

Suppose you have this function:

foo(int v, int w, int x, int y, int z)

Then the call

foo(3, 4, 5, 6, 7)

is easy to understand, even if you have to know which order the 
arguments appear. But make x, y, and z named parameters, and you 
have

foo(3, 4, x=5, y=6, z=7)
foo(3, x=5, 4, y=6, z=7)
foo(3, x=5, y=6, 4, z=7)
foo(3, x=5, y=6, z=7, 4)

all evaluating to the same thing, and somehow the programmer is 
supposed to know that the 4 is mapped to the second argument in 
every call. This is the kind of thing that would make someone 
give up on D after just a few minutes. The only way it can work 
to rearrange the mapping of parameters from the function call to 
the function itself is if the parameter being moved is named. 
This is a simple example. If you had several named and several 
unnamed parameters it would lead to a lot of confusion.



More information about the Digitalmars-d mailing list