<div class="gmail_quote">On Fri, Aug 27, 2010 at 4:00 PM, Jonathan M Davis <span dir="ltr"><<a href="mailto:jmdavisprog@gmail.com">jmdavisprog@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On Friday 27 August 2010 11:42:54 Andrei Alexandrescu wrote:<br>
> I think I mentioned this - the Timer class we use at work has startup<br>
> dictated by true/false. Most of the code I'm reviewing uses:<br>
><br>
> Timer timer;<br>
> timer.start();<br>
><br>
> thus wasting a vertical line (precious) over the simpler but confusing:<br>
><br>
> Timer timer(true);<br>
><br>
> Another example from real code:<br>
><br>
> serialize(output, data, true, true);<br>
><br>
> The first true means use Base64 encoding. The second means use compression.<br>
<br>
</div>Oh, I get what you're saying, and I don't exactly think that you're wrong. I<br>
just think that in many cases, bool works just fine. You often have to look up<br>
the function anyway, so the added clarity isn't much, and the added verboseness<br>
can be irritating. Obviously it can become a problem if you have multiple bools,<br>
and using enums instead can improve clarity in many cases, so using enums does<br>
have its advantages. When it comes down to it, I don't really have any problem<br>
with using an enum, but I don't really have a problem with bool either.<br>
Honestly, I don't think that it ever would have occurred to me to use anything<br>
but an enum did you not propose that enums should be used instead in Phobos.<br>
<br>
In any case, I've been using the enum model in the date/time code that I've been<br>
writing, so you won't have to worry about stray bool parameters in there.<br>
<font color="#888888"><br>
- Jonathan M Davis<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
phobos mailing list<br>
<a href="mailto:phobos@puremagic.com">phobos@puremagic.com</a><br>
<a href="http://lists.puremagic.com/mailman/listinfo/phobos" target="_blank">http://lists.puremagic.com/mailman/listinfo/phobos</a><br>
</div></div></blockquote></div><br>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).<br>