DIP 1019--Named Arguments Lite--Community Review Round 2

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Jun 9 19:42:19 UTC 2019


On 6/9/19 7:15 AM, aliak wrote:
> On Sunday, 9 June 2019 at 07:51:18 UTC, Andrei Alexandrescu wrote:
>> On 6/8/19 2:05 PM, Jonathan Marler wrote:
>>> I see value in allowing a caller to omit arguments that have default 
>>> values, but what is the value in allowing the caller to reorder them?
>>
>> Named arguments is useful mainly so one doesn't need to remember their 
>> order in large argument lists.
> 
> When has anyone had a problem with unreorderable named arguments in 
> functions with large argument lists?

This is a leading question. When has anyone hadn't?

> After using languages with unreorderable and reorderable named 
> parameters. I only see a very mild benefit of programmer laziness for 
> reorderable, and the larger downside of reader annoyance. I've felt no 
> downsides of unreorderable (you generally look at the documentation, and 
> type it in param by param, or copy paste the declaration, and if you get 
> it wrong, the compiler tells you and you fix it).

What would be those languages? The Wikipedia page 
https://en.wikipedia.org/wiki/Named_parameter mentions:

"With named parameters, it is usually possible to provide the values in 
any arbitrary order, since the name attached to each value identifies 
its purpose. This reduces the connascence between parts of the program. 
A few languages use named parameters but still require the parameters to 
be provided in a specific order."

So it looks like reordering is prevalently supported. The page 
https://rosettacode.org/wiki/Named_parameters mentions that the 
following languages do not support reordering (upon a quick look): 
Elixir, Fortran, Nemerle.

Is this the company we want to be in? From what I see in a few popular 
languages:

* Python: reordering is a feature. From 
https://treyhunner.com/2018/04/keyword-arguments-in-python: "When we use 
keyword/named arguments, it’s the name that matters, not the position"

* C# 4: reordering is a feature. From 
https://en.wikipedia.org/wiki/C_Sharp_4.0#Optional_parameters_and_named_arguments: 
"Parameter names can be specified for both optional and required 
parameters, and can be used to improve readability or arbitrarily to 
reorder arguments in a call."

* Ruby: reordering is a feature. From 
https://thoughtbot.com/blog/ruby-2-keyword-arguments: "Keyword arguments 
allow us to switch the order of the arguments, without affecting the 
behavior of the method"

* Scala: reordering is a feature. From 
https://docs.scala-lang.org/tour/named-arguments.html: "Notice how the 
order of named arguments can be rearranged."

That's why the "Related Work" section is crucial. It needs to make a 
careful account of experience in existing languages. For my money, named 
arguments with no reordering means we're wasting our time.


More information about the Digitalmars-d mailing list