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

arturg var.spool.mail700 at gmail.com
Mon Apr 1 20:36:47 UTC 2019


On Monday, 1 April 2019 at 19:41:25 UTC, bachmeier wrote:
> On Monday, 1 April 2019 at 13:21:48 UTC, rikki cattermole wrote:
>
>> [...]
>
> 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.

Whats the big issue with named parameters, why cant D have them 
with the same restriction as C#?

foo(3, 4, x=5, y=6, z=7) works
foo(3, x=5, 4, y=6, z=7) does'nt, because every paremeter after a 
named one has to be a named parameter


More information about the Digitalmars-d mailing list