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

RazvanN razvan.nitu1305 at gmail.com
Mon Feb 18 08:52:38 UTC 2019


On Monday, 18 February 2019 at 08:32:02 UTC, RazvanN wrote:
> On Sunday, 17 February 2019 at 21:04:23 UTC, Yuxuan Shui wrote:
>> [...]
>
> How about this: simply adding the ability to name the argument 
> when calling a function? Example:
>
> void rectangle(int width, int height) {}
>
> void main()
> {
>     rectangle(1, 2);
>     rectangle(width: 1, height: 2);
>     rectangle(height: 2, width: 1);
>     rectangle(width: 1, 2);    // error
> }
>
> All 3 function invocations lower to the same function call. Of 
> course, naming should be either for all parameters or for none. 
> This has the advantage that no code will be broken and naming 
> will become optional. This way you have no mangling problems 
> and you don't have to add any attributes.
>
> This solution is also easier to implement and easier to 
> drop/enhance after we gather some information about where we 
> need to go with this.
>
> Cheers
> RazvanN


I forgot to mention optional parameters; if there are any 
optional parameters and you are fine with the default value, you 
don't have to specify them.


More information about the Digitalmars-d mailing list