DIP 1030--Named Arguments--Community Review Round 1 Discussion

matheus matheus at gmail.com
Fri Feb 7 19:59:41 UTC 2020


On Friday, 7 February 2020 at 19:26:10 UTC, H. S. Teoh wrote:
> ...
> However, I *have* also found myself desiring nameable arguments 
> for the sake of self-documenting code, for example:
>
> 	myRange.process(nRetries: 2);
>
> as opposed to:
>
> 	myRange.process(2); // what does '2' mean?!
> ...

Yes this is one case that people will argue in favor of named 
arguments, but on the other hand I would point out: Why is he 
using a magic number in a code? :)

A define/enum/variable would fix this issue, at least in most 
documentations I read I usually see variables to explain the 
"expected parameters".

Another thing is current Editors/IDE help with this problem too, 
they show what parameters a function is expected even the 
overloads while you typing.

By the way one interesting and funny thing in C# documentation:

https://docs.microsoft.com/en-us/dotnet/api/system.dayofweek?view=netframework-4.8#examples

You will see a example of DateTime usage like this:

> // Assume the current culture is en-US.
> // Create a DateTime for the first of May, 2003.
>    DateTime dt = new DateTime(2003, 5, 1);

They didn't even bother to use named arguments there. They just 
warned about culture en-US. :)

Well in my opinion I would prefer to see development in other 
areas than in this particular case.

Matheus.


More information about the Digitalmars-d mailing list