DIP Draft Review News

rikki cattermole rikki at cattermole.co.nz
Mon Jun 4 10:30:18 UTC 2018


On 04/06/2018 10:05 PM, Yuxuan Shui wrote:
> On Monday, 4 June 2018 at 05:46:04 UTC, rikki cattermole wrote:
>> On 04/06/2018 5:01 PM, Mike Parker wrote:
>>> Named arguments lite
>>
>> I'm concerned about this DIP (keep in mind I wrote a referenced WIP DIP).
>>
>> 1. Reordering of parameters that match (with overloads)
>>
>> ```D
>> int add(int a, int b);
>> int add(int b, int a) { ... }
>> ```
>>
>> This part of the DIP needs quite a bit of filling out and I expect to 
>> have a lot of corner cases.
>>
>> Are you saying that you have an add that is extern'd or do you mean a 
>> named argument function overload? By conventional wisdom it definitely 
>> should error out.
> 
> Not sure what you meant? This definitely does not error out: 
> https://godbolt.org/g/PAiFPw

```D
@named:
int add(int a, int b);
int add(int b, int a) {
	assert(a > 0);
	return a + b;
}

void main() {
	add(2, 0);
}
```

>>
>> 2. All or nothing.
>>
>> ```D
>> int add(int x, int y);
>> @named:
>> int add(int b, int a) { ... }
>> ```
>>
>> This is one of the reasons some people /don't/ want named arguments 
>> and have said that they out right would not use a language with it.
>>
> 
> Care to elaborate why? In this DIP, name prefix on caller side is 
> optional, caller is allowed to leave out any number of argument names if 
> they want.

Not all parameters should be used as named arguments. Two syntax's one 
purpose isn't desired, which the DIP currently encourages.

Personally I want to keep named and unnamed completely separate and 
focus more upon public API.



While I'm not keen on 2 and definitely would love for 3, my first point 
is what will determine if I vote yes or not (assuming it gets there). My 
instincts are saying that it simply hasn't been thought through enough 
just yet and that there will be some real trouble with it.

Ambiguity is nobody's friend when it comes to programming language 
proposals. You have time to think it over, and I could be very wrong (of 
course); but other wise as a lite version of named arguments its not a 
bad DIP, just maybe we can do better for D ;)


More information about the Digitalmars-d-announce mailing list