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

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Feb 7 19:26:10 UTC 2020


On Fri, Feb 07, 2020 at 07:02:14PM +0000, matheus via Digitalmars-d wrote:
> On Friday, 7 February 2020 at 03:33:26 UTC, Jonathan M Davis wrote:
> > Well, I'll say again that I don't like the idea of having named
> > arguments in the language, because it makes the parameter names part
> > of the API, resulting in yet more bikeshedding and yet another thing
> > that can't be changed without breaking existing code. Once in a
> > while, named arguments may be useful, but for the most part, they're
> > useful because a function has way too many parameters, in which
> > case, the function should have been designed differently.
> 
> +1. I never used this feature in C# for example.
> 
> Like you said:
> 
> "...named arguments may be useful, but for the most part, they're
> useful because a function has way too many parameters, the function
> should have been designed differently.".
[...]

I agree that this tends to be the use case, and I agree that when the
number of function parameters exceed a certain threshold, it should be
designed differently. At the very least, the parameters should be
factored into a struct that can then be initialized by the caller and
passed in as a whole, rather than isolated arguments.

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?!

I can't say this is always desirable, but there are situations where it
would be nice, maybe because the parameter is optional, or tangential to
the function's main purpose, so it's not immediately obvious what it
does.  There are definitely times when I'd say this is a sign of bad
API design, but I also can't say that 100% of the time. As with all
things, there are exceptions, and in the exceptional cases named
arguments can be just the thing to fill that need.


T

-- 
It's bad luck to be superstitious. -- YHL


More information about the Digitalmars-d mailing list