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

a11e99z black80 at bk.ru
Thu Sep 12 14:37:44 UTC 2019


On Thursday, 12 September 2019 at 13:44:52 UTC, Paul Backus wrote:
> On Thursday, 12 September 2019 at 12:19:51 UTC, a11e99z wrote:
>> On Thursday, 12 September 2019 at 12:15:57 UTC, a11e99z wrote:
>>> On Thursday, 12 September 2019 at 11:46:46 UTC, rikki 
>>> cattermole wrote:
>>>> On 12/09/2019 11:29 PM, Yuxuan Shui wrote:
>>
>> naming args is not mandatory.
>> using names depends from user of lib not from lib itself or 
>> compiler.
>
> In DIP 1020, naming arguments is mandatory.

this is not good.

it was not good cuz method can be called with mixing named and 
positional args
> func( 1, z: 3, y: 2, 4 ); // and comma is float-dot for some 
> human langs
and optional can be mixed(before) with required args
> void func( int one, float two =2, string three ) { }

and now is not good from other side:
u can not call method without naming args when @named exists in 
definition.

"out of the frying pan into the fire"

I dont like such named args.

---------------------
I like C# naming more and more:
- defaulted/optional args only in the end of args list (function 
definition).
- naming args is not mandatory (function call).
- named args only after positional/required args not intermixing 
(func call).
- order for named args doesn't matter (func call).
- required/positional/non-defaulted args should be assigned (func 
call).
- and assigning arg more than once is error.

> void func( int one, float two =5, string three ); // ERROR. 
> optional before required.
> void func( int one, float two, string three, int four = 123, 
> float five = 3.14 );

> func( 1, 2, "3", 4, 5 ); // OK
> func( 1, five: 2.72, 2, four: 321, three: "hello" ); // ERROR. 
> named before positional
> func( 1, five: 3e8, four: 4, three: "3", two: 2 ); // OK
> func( 1, 2, four: 321 ); // ERROR. required "three" is not 
> assigned
> func( 1, three: "hello", two: 2 ); // OK
> func( 1, 2, three: "hello", two: 2 ); // ERROR. "two" assigned 
> twice
---------------------

what the reason do mandatory naming for @named args?
arg names will also be involved in choosing the right method 
along with overloading and templates and UFCS?



More information about the Digitalmars-d mailing list