DIP 1019--Named Arguments Lite--Final Review
a11e99z
black80 at bk.ru
Sat Aug 24 07:54:57 UTC 2019
On Saturday, 24 August 2019 at 07:18:56 UTC, Nick Treleaven wrote:
> 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).
imo named args needed for one purpose only:
when u remember name of arg but don't remember which one (by
natural order) it is.
when u don't remember name but only position most probably u also
remember what is it at position before.
do u know other reasons for named args?
so from that point lets look at
> f(a: 1, 2, d: 5)
- u don't remember where a is, so named it
- u remember that b is second, so let it unnamed
(dont remember 1st one but remember 2nd.. hmm)
- and other defaults, doesn't matter their order
same situation from another point: u reviewing code of ur junior.
u see this. what u will do? most probably "don't do this! yes, u
can but don't".
so why u tell me now that this is right way?
mixing named then unnamed then named again its just a new weird
shit in lang.
PS
remember about DPP when tons of C++ code with tons of overloads
will come to D
More information about the Digitalmars-d
mailing list