Flag proposal

Torarin torarind at gmail.com
Fri Jun 10 13:25:53 PDT 2011


2011/6/10 Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>:
> On 6/10/11 1:52 PM, Robert Clipsham wrote:
>>
>> On 10/06/2011 19:06, Andrei Alexandrescu wrote:
>>>
>>> On 6/10/11 12:42 PM, Robert Clipsham wrote:
>>>>
>>>> On 10/06/2011 17:15, Andrei Alexandrescu wrote:
>>>>>
>>>>> https://github.com/D-Programming-Language/phobos/pull/94
>>>>>
>>>>> Discuss!
>>>>>
>>>>> Andrei
>>>>
>>>> I really *really* don't like this. It's ugly and verbose, and a pathetic
>>>> work around for the lack of named parameters. Either support named
>>>> parameters or not, don't have an ugly half-baked work-around.
>>>
>>> This is not half-baked. It's pretty much it.
>>
>> My choice of wording was poor, sorry.
>>
>>> Ugly is in the eye of the beholder, but I fail to see how the added
>>> punctuation makes Flag!"param".yes significantly more verbose than param
>>> : true.
>>
>> foo(param: true, otherParam: false);
>> foo(Flag!"param".yes, Flag!"otherParam".no);
>>
>> I don't know about you, but I find the former is far more legible. I'd
>> hate to see my code littered with Flag!"something".
>
> I agree it's more legible. The crucial question is whether the added
> legibility warrants adding a new feature to the language.
>
>>> The problem that named parameters are still optional remains. Or we need
>>> to add one extra language feature to specify required named parameters.
>>
>> void foo(bool param, bool otherParam, bool thisOneIsntRequired = false);
>>
>> Call it with or without named parameters, two are required, one is not.
>>
>> foo(otherParam: true, param: false);
>> foo(true, false);
>> foo(otherParam: true, param: false, thisOneIsntRequired: true);
>>
>> Would all be valid.
>
> The second call is problematic because it still allows bad style in calls.
>
>
> Andrei
>

I agree, introducing a syntax for required named parameters sounds
like it would entail baggage of similar weight.

Torarin


More information about the Digitalmars-d mailing list