DIP 1019--Named Arguments Lite--Community Review Round 1
12345swordy
alexanderheistermann at gmail.com
Fri Feb 15 21:15:20 UTC 2019
On Friday, 15 February 2019 at 21:05:38 UTC, Golden Rockefeller
wrote:
> On Friday, 15 February 2019 at 12:56:45 UTC, Mike Parker wrote:
>> This is the feedback thread for the first round of Community
>> Review for DIP 1019, "Named Arguments Lite":
>>
>> https://github.com/dlang/DIPs/blob/23ef47a94e0fdd5ddc4b2f6b2f4dcfd3c1f43aa6/DIPs/DIP1019.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 March 1, 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.
>
> As another alternative, named parameters can be implemented
> using Tuple/tuple from the Phobos Library. This alternative
> solution will prevent silent breakage. The caller can not
> opt-out. This solution adds even more noise to function calls
> but typedef can reduce the noise. This solution does not
> address reordering but can be combined with other solutions
> that allow for reordering. Here is an example:
>
>
> import std.typecons;
> double get_area(Tuple!(double, "radius") t_radius) {
> double radius = t_radius.radius;
> return 3.14 * radius * radius;
> }
>
> double get_area(Tuple!(double, "diameter") t_diameter) {
> double radius = t_diameter.diameter / 2;
> return 3.14 * radius * radius;
> }
>
> void main()
> {
> import std.stdio;
> auto area = get_area(tuple!"radius"(4.));
> writeln("Area with radius: ", area);
> area = get_area(tuple!"diameter"(8.));
> writeln("Area with diameter: ", area);
> }
The downside to your solution is an increases in memory.
More information about the Digitalmars-d
mailing list