[phobos] phobos commit, revision 1919

David Simcha dsimcha at gmail.com
Fri Aug 27 13:12:23 PDT 2010


On Fri, Aug 27, 2010 at 4:00 PM, Jonathan M Davis <jmdavisprog at gmail.com>wrote:

> On Friday 27 August 2010 11:42:54 Andrei Alexandrescu wrote:
> > I think I mentioned this - the Timer class we use at work has startup
> > dictated by true/false. Most of the code I'm reviewing uses:
> >
> >      Timer timer;
> >      timer.start();
> >
> > thus wasting a vertical line (precious) over the simpler but confusing:
> >
> >      Timer timer(true);
> >
> > Another example from real code:
> >
> >      serialize(output, data, true, true);
> >
> > The first true means use Base64 encoding. The second means use
> compression.
>
> Oh, I get what you're saying, and I don't exactly think that you're wrong.
> I
> just think that in many cases, bool works just fine. You often have to look
> up
> the function anyway, so the added clarity isn't much, and the added
> verboseness
> can be irritating. Obviously it can become a problem if you have multiple
> bools,
> and using enums instead can improve clarity in many cases, so using enums
> does
> have its advantages. When it comes down to it, I don't really have any
> problem
> with using an enum, but I don't really have a problem with bool either.
> Honestly, I don't think that it ever would have occurred to me to use
> anything
> but an enum did you not propose that enums should be used instead in
> Phobos.
>
> In any case, I've been using the enum model in the date/time code that I've
> been
> writing, so you won't have to worry about stray bool parameters in there.
>
> - Jonathan M Davis
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>

I generally prefer enums in public or package APIs (because they're more
descriptive and not that much more verbose), but bools in module- or
class/struct-private functions (because this way I don't have to define yet
another type that I'm only going to use in a few places and not that many
other people have to understand the code).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100827/dd3f98e1/attachment.html>


More information about the phobos mailing list