<html><body bgcolor="#FFFFFF"><div>This idiom works but only for classes and small structs.<br><br>Sent by shouting through my showerhead.</div><div><br>On Aug 27, 2010, at 10:16 PM, Daniel Murphy &lt;<a href="mailto:yebblies@gmail.com">yebblies@gmail.com</a>&gt; wrote:<br><br></div><div></div><blockquote type="cite"><div>I understand that using an enum is the normal phobos way to do this, but would the following be acceptable?<div><br></div><div>auto sw = StopWatch().start();</div><div><br></div><div>I've used this design in C++ before. &nbsp;Would this be acceptable for D/phobos?<br>
<br><div class="gmail_quote">On Sat, Aug 28, 2010 at 6:12 AM, David Simcha <span dir="ltr">&lt;<a href="mailto:dsimcha@gmail.com"><a href="mailto:dsimcha@gmail.com">dsimcha@gmail.com</a></a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5"><div class="gmail_quote">On Fri, Aug 27, 2010 at 4:00 PM, Jonathan M Davis <span dir="ltr">&lt;<a href="mailto:jmdavisprog@gmail.com" target="_blank"><a href="mailto:jmdavisprog@gmail.com">jmdavisprog@gmail.com</a></a>&gt;</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>On Friday 27 August 2010 11:42:54 Andrei Alexandrescu wrote:<br>
&gt; I think I mentioned this - the Timer class we use at work has startup<br>
&gt; dictated by true/false. Most of the code I'm reviewing uses:<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;Timer timer;<br>
&gt; &nbsp; &nbsp; &nbsp;timer.start();<br>
&gt;<br>
&gt; thus wasting a vertical line (precious) over the simpler but confusing:<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;Timer timer(true);<br>
&gt;<br>
&gt; Another example from real code:<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;serialize(output, data, true, true);<br>
&gt;<br>
&gt; 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>_______________________________________________<br>
phobos mailing list<br>
<a href="mailto:phobos@puremagic.com" target="_blank"><a href="mailto:phobos@puremagic.com">phobos@puremagic.com</a></a><br>
<a href="http://lists.puremagic.com/mailman/listinfo/phobos" target="_blank"><a href="http://lists.puremagic.com/mailman/listinfo/phobos">http://lists.puremagic.com/mailman/listinfo/phobos</a></a><br>
</div></div></blockquote></div><br></div></div>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>

<br>_______________________________________________<br>
phobos mailing list<br>
<a href="mailto:phobos@puremagic.com"><a href="mailto:phobos@puremagic.com">phobos@puremagic.com</a></a><br>
<a href="http://lists.puremagic.com/mailman/listinfo/phobos" target="_blank"><a href="http://lists.puremagic.com/mailman/listinfo/phobos">http://lists.puremagic.com/mailman/listinfo/phobos</a></a><br></blockquote></div><br></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>phobos mailing list</span><br><span><a href="mailto:phobos@puremagic.com">phobos@puremagic.com</a></span><br><span><a href="http://lists.puremagic.com/mailman/listinfo/phobos">http://lists.puremagic.com/mailman/listinfo/phobos</a></span></div></blockquote></body></html>