DIP 1019--Named Arguments Lite--Final Review
Nick Treleaven
nick at geany.org
Sat Aug 24 07:18:56 UTC 2019
On Friday, 23 August 2019 at 19:57:05 UTC, a11e99z wrote:
> On Friday, 23 August 2019 at 19:48:59 UTC, Paul Backus wrote:
>> struct S { int a, b, c, d = 7; }
>> S w = { b:1, 3 }; // v.a = 0, v.b = 1, v.c = 3,
>> v.d = 7
>
> unnamed arg after named is weird/error prone
It is fine, but only when the named argument has the same
position as it would if it were unnamed.
void f(int a, b, c = 3, d = 4);
//Equivalent calls:
f(a: 1, 2, d: 5);
f(1, 2, 3, 5);
The purpose of writing `a: 1` is to describe the argument to the
function at the call site, as programmers often won't look up the
function signature just when reading code (e.g. on GitHub when
they don't have the function open in their IDE).
Why not name b's argument too? Because that argument might be
more obvious what it is. a might be passed a primitive literal
but b might be passed a variable with the same name (or
equivalent).
More information about the Digitalmars-d
mailing list