Flag proposal

Michel Fortin michel.fortin at michelf.com
Fri Jun 10 13:34:26 PDT 2011


On 2011-06-10 16:10:51 -0400, Andrei Alexandrescu 
<SeeWebsiteForEmail at erdani.org> said:

> On 6/10/11 2:12 PM, Michel Fortin wrote:
>> I have to say I totally agree with Robert.
>> 
>> I agree with the need for a way to name parameters, but instantiating a
>> pseudo-boolean type from a template for each function parameter is worse
>> than the initial problem. Templates are already a difficult concept to
>> grasp for most people (because they're so abstract), we really don't
>> need to replace every boolean parameter with a template type.
> 
> I disagree with the "templates are difficult" mantra. It is a meme from 
> C++ much like "macros are evil" are one from C. It's a simple 
> construct, you use it.

Neither C macros nor C++ or D templates are very difficult by 
themselves. People trying to do unintuitive but clever things with them 
earned them this reputation.

If you want something to be used everywhere and it is not an 
implementation detail, make it part of the language. Implementing what 
sounds should be a language feature through a template hack and putting 
it the standard library is not going to make people feel good about the 
language, it'll remind them of what the language is missing.


>> And just try to think of the signature for the function above if it was
>> using Flag!
>> 
>> void foo(Flag!"param" param, Flag!"otherParam" otherParam,
>> Flag!"thisOneIsntRequired" thisOneIsntRequired =
>> Flag!"thisOneIsntRequired".no);
>> 
>> Do we really want to expose that in the documentation?
> 
> Yes, that's the whole point, though I agree the hiccup in the default 
> initializer is annoying.

I find it funny that you see a hiccup only in the default initializer 
when the name of all parameter is also duplicated in its type. 
Shouldn't that be 4 hiccups?


> The documentation doesn't need the names anymore; the user would just say:
> 
> void foo(
>    Flag!"compressed",
>    Flag!"encrypted",
>    Flag!"buffered" = Flag!"buffered".no);
> 
> Save for the "ehm" default parameter this looks palatable to me.

Does that mean we now need a language feature to tell the documentation 
generator not to emit attribute names for parameters of type Flag!"" ?


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list