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

Steven Schveighoffer schveiguy at gmail.com
Sun Feb 9 18:32:45 UTC 2020


On 2/8/20 11:10 PM, Jon Degenhardt wrote:
> For Phobos this would be my expectation as well. I'm admittedly thinking 
> of project environments with meaningful size teams more than the 
> standard library of a major programming language. Environments where 
> there is a fair bit of code in earlier stages of development and subject 
> to more evolution.

I think the evolution goes like this:

void foo(int tmpName);

...

// all callers:

foo(5); // didn't use named parameters because I have no idea what 
"tmpName" means

now, we evolve foo:

void foo(int milliseconds);

Now, all calls still work because nobody used the bad name as 
"documentation". New calls now use the name sometimes because it's 
helpful. My point is simply that the name itself is going to not 
require, but probably result in, people using or not using the name. Bad 
names naturally aren't going to get name usage, because they suck and 
aren't helpful. Good names are.

I understand though, there are possible bikeshed problems here. For 
example, someone who implements foo might be tired of typing out 
"milliseconds" and change the parameter name to "ms". Now that person 
has to worry about what happens for callers. So instead he has to leave 
milliseconds in the name, and create a temporary ms in his function. At 
that point, you have to weigh how important it is to change that 
parameter name against the breakage that might occur. How much does it 
cost to repaint the shed? Might not be worth it.

Note that Swift (which has parameter names as part of the function name) 
has a mechanism to deal with this.

A function in swift looks like:

func foo(a : int) -> Void

You MUST call the function with foo(a: 5). foo(5) doesn't work.

But you can name the parameter to the outside and name the parameter 
differently on the inside:

func foo(milliseconds a: int) -> Void

Now, you call the function with foo(milliseconds: 5), and inside the 
function, the parameter is named 'a'.

Not sure this could be doable in D. But for a main language that started 
out with significant naming of parameters (inheriting this from 
objective-C), it's a good place to look for inspiration here.

-Steve


More information about the Digitalmars-d mailing list