DIP 1030--Named Arguments--Community Review Round 1 Discussion
Steven Schveighoffer
schveiguy at gmail.com
Wed Feb 12 20:11:14 UTC 2020
On 2/12/20 2:44 PM, SashaGreat wrote:
> On Wednesday, 12 February 2020 at 07:42:32 UTC, aliak wrote:
>> Named arguments is the difference between spending 1 second looking at
>> this:
>>
>> makeWindow(x: 67, y: 98, width: 100, height: 100)
>>
>> Or taking about 1 to 5 minutes depending on how easy documentation is
>> to find, and how bored you are to figure out what this is doing:
>>
>> makeWindow(67, 98, 100, 100)
>
> You're using an example in favor of a point, because it's hard to
> someone use constants for this kind of thing for a production code, at
> least for obvious reasons it shouldn't.
>
> Now let's compare:
>
>> makeWindow(x: 67, y: 98, width: 100, height: 100)
>
> With:
>
> makeWindow(x, y, width, height);
>
> Of course 'x', 'y', 'width' and 'height' are variables defined
> elsewhere, but it's less noisy.
I agree with you! But it depends on the situation.
I'll embelish with something else.
Let's say that you have variables for some and you want to put in
literals for others, which do you prefer?
makeWindow(67, 98, width, height)
or
makeWindow(x: 67, y: 98, width, height)
You see, you can use named parameters when it makes sense, and not when
it doesn't. I think this is really just a greater mechanism to make
calls more self-documenting, and code much easier to read and understand.
> Now to be honest I would prefer for this particular function to use a
> struct like "myWindow" to define the coordinates:
>
> makeWindow(myWindow);
This is just named parameters with extra types needed. Same as the Flag
case. Removing all that cruft from the library and language is a net-win.
And it doesn't help when you want to use expressions to generate new
parameters -- the code is going to be ugly because you first have to
construct a typeof(myWindow).
> I barely use name parameters for languages that support and to be honest
> I barely see than in other codes.
My second most used language is Swift, which requires named parameters.
There are some cool things you can do with function and parameter names
when they are significant. I think it's going to be a net benefit. We
just have to resolve the introspection issue.
-Steve
More information about the Digitalmars-d
mailing list