On 6/10/11 2:12 PM, Michel Fortin wrote:
On 2011-06-10 14:52:53 -0400, Robert Clipsham
<rob...@octarineparrot.com> said:
On 10/06/2011 19:06, Andrei Alexandrescu wrote:
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 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.
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);
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. 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.
Andrei