DIP 1020--Named Parameters--Community Review Round 1

Q. Schroll qs.il.paperinik at gmail.com
Fri Apr 5 00:17:02 UTC 2019


On Sunday, 31 March 2019 at 12:33:56 UTC, Mike Parker wrote:
> This is the feedback thread for the first round of Community 
> Review for DIP 1020, "Named Parameters":
>
> https://github.com/dlang/DIPs/blob/39dbbbe5e4618abd4c4b41eb0edd16547858ddf5/DIPs/DIP1020.md
>
> All review-related feedback on and discussion of the DIP should 
> occur in this thread. The review period will end at 11:59 PM ET 
> on April 14, or when I make a post declaring it complete.
>
> At the end of Round 1, if further review is deemed necessary, 
> the DIP will be scheduled for another round of Community 
> Review. Otherwise, it will be queued for the Final Review and 
> Formal Assessment by the language maintainers.
>
> Please familiarize yourself with the documentation for the 
> Community Review before participating.
>
> https://github.com/dlang/DIPs/blob/master/PROCEDURE.md#community-review
>
> Thanks in advance to all who participate.

There are a couple of versions a parameter in a function can be 
syntactically appear:

void f(int param = 0); // named with default value
void f(int param); // named without default value
void f(int = 0); // unnamed with default value
void f(int); // unnamed without default value

Named arguments must be compatible with at least the named 
variants. It must not be disturbed by the others.

A bigger issue are template arguments -- here the variety is even 
bigger:

template t(T) { }
template t(T : S) { } // *
template t(T = int) { }
template t(T : S = int) { }

plus any value parameter (see above)

alias parameters probably can be handled as if `alias` were the 
type in the value parameter case.

The starred one indicates that the colon is a nontrivial option 
for named arguments. First, it must not interfere with the 
type-colon, and it must be clear enough for programmers reading 
the code.

I strongly believe that the most viable solution is a new token 
:= which should be used at caller and/or callee site. Like:

void f(int param = 0 := arg);
f(arg := value);

It's obviously compatible with anything and reads nicely. In 
fact, Visual Basic uses this at call site.

1. Should the callee have to specify argument names to make 
calling with named arguments possible? I don't know.
2. Should multiple namings be possible, i.e. overload by argument 
name? No. Name the function differently.
3. Should reordering be possible? If ever, only if *all* 
parameters are named and naming at call site necessary.
4. Should we wait until struct initialization? Yes. It can solve 
much of that.



More information about the Digitalmars-d mailing list