DIP 1019--Named Arguments Lite--Community Review Round 2
Guillaume Boucher
guillaume.boucher.d at outlook.com
Wed Jun 5 23:00:29 UTC 2019
On Wednesday, 5 June 2019 at 13:03:26 UTC, Mike Parker wrote:
> This is the feedback thread for the second round of Community
> Review for DIP 1019, "Named Arguments Lite":
>
> https://github.com/dlang/DIPs/blob/9c9cc39246de4c449fe1e6cb6b27f7e426ff1eb9/DIPs/DIP1019.md
Quoting the DIP:
> Future changes
>
> This DIP does not prohibit future proposals for adding
> parameter reordering, partially-specified parameter names with
> reordering, named template parameters, omission of default
> arguments by using named arguments, and other similar things.
> Nor does it prohibit the inclusion of parameter names as part
> of mangled function names.
I'd argue this claim is false.
Forward declarations don't work together with those things nicely:
```
int f(int a, int b);
int f(int b, int a) {...}
void main() {
f(a: 1, b: 2); // according to the DIP, this calls f(2, 1)
}
```
What happens if parameter reordering are supported? If you're
consistent with the rest of D, the call needs to be changed to
f(1, 2). Which is a silent breakage!
That's because in D the definition has somehow more weight than
the forward declarations:
```
void f(int a=1);
void f(int a=2);
void f(int a) { ... }
void g(int a=1);
void g(int a=2) { ... }
void main() {
f(); // Error: f called with argument types () matches both:
f(int a = 1) and f(int a = 2)
g(); // calls g(2)
}
```
The only way I see to sanely introduce reordering would be to
treat forward declarations and the definition equally and refuse
to compile if there's any ambiguity. Which is a fairly impactful
change that breaks code, even if that code doesn't use named
arguments.
So unless someone has a good idea how to deal with those cases,
I'd say:
- named arguments without forward declarations are fine (we can
add more stuff later without problems)
- named arguments with forward declarations, i.e. the current
DIP, blocks a later addition of reordering unless you accept code
breakage
- named arguments with forward declarations AND reordering right
away are fine too, but require a spec that is a little bit
inconsistent with the rest of D.
More information about the Digitalmars-d
mailing list