Flag proposal

Lutger Blijdestijn lutger.blijdestijn at gmail.com
Fri Jun 10 14:17:23 PDT 2011


Nick Sabalausky wrote:

> "Nick Sabalausky" <a at a.a> wrote in message
> news:istv62$2skn$1 at digitalmars.com...
>> "Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message
>> news:isttf6$2oub$1 at digitalmars.com...
>>> On 6/10/11 1:52 PM, Robert Clipsham wrote:
>>>>
>>>> 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.
>>>
>>
>> I really see Flag more as a way to try to rationalize avoiding adding
>> named parameters to the language.

I don't, even though I like named parameters. boolean parameters for binary 
options are kind of an exception imho, because they decrease readability at 
the call site much more often than other types do.

Somebody one this newsgroup - maybe it was Don Clugston, also made a good 
point against named parameters: it introduces inflexibility because now the 
names of the parameters of a function become part of the public api. 
Changing a name will now break client code.

I'd still probably welcome named parameters though.

>> And yes, the legibility of "foo(Flag!"param".yes,
>> Flag!"otherParam".no);", combined with the frequency of need for such a
>> thing, and the complete inability of Flag to address the problem for
>> anything but bool, the inability to document it separately (as Jonathan
>> Davis pointed out), is all definitely much much more than enough to
>> warrant adding a tried-and-proven feature that's become standard in damn
>> near every other modern language.
>>
> 
> Regarding "the complete inability of Flag to address the problem for
> anything but bool", how are we going to wind up papering over that?
> 
> Like:
> 
> box(Int!"x"(3), Int!"y"(4), Int!"width"(100), Int!"height"(150),
> Int!"depth"(1), UInt!"color"(0xFFAA77));
> 
> ?


More information about the Digitalmars-d mailing list