Flag proposal

KennyTM~ kennytm at gmail.com
Mon Jun 13 23:18:42 PDT 2011


On Jun 14, 11 09:36, so wrote:
> On Mon, 13 Jun 2011 20:19:15 +0300, bearophile <
> <bearophileHUGS at lycos.com> wrote:
>
>> Andrei:
>>
>>> If we all get convinced that named parameters are worth it,
>>
>> I think this is not going to happen because some people (two?) don't
>> want this feature.
>
> I think they worth it and it is the right time to talk extensively why
> people think they don't.
> And reasoning should not be about its failure or success in another
> language, we better have our own rules.
>
> IMO named arguments in D at least should do:
>
> - Reordering (since we got default parameters, even better)
>
> - It is enabled only if we have access to the function declaration.
>
> - In a function call we either use named arguments for all the
> non-default arguments or call it with the usual syntax. No hybrid stuff,
> no confusion.
>
> fun(int a, int b, int c=3)
>
> fun(1, 2, 3) // fine - current
> fun(1, 2) // fine - current
>
> fun(a:1, b:3, c:5) // fine
> fun(a:1, b:3) // fine
> fun(b:1, c:3, a:5) // fine
> fun(b:1, a:3) // fine
> fun(b:1) // error
> fun(c:1) // error
> fun(2, b:1) // error
> fun(2, c:1) // error
> fun(2, c:2, 3) // error
>
> Thanks.

I'd rather have no reordering and allow hybrid call. Named argument is 
useful for specifying the nature of an argument. If the type is clear 
for all but one argument, the rest is just noisy redundant info.

e.g.

     MoveWindow(hWnd, loc.x, loc.y, myWin.width, myWin.height,
                bRepaint:true);

is no worse than

     MoveWindow(hWnd:hWnd, X:loc.x, Y:loc.y,
                nWidth:myWin.width, nHeight:myWin.height, bRepaint:true);



More information about the Digitalmars-d mailing list