<div dir="ltr">Hi Brad,<div><br></div><div>Even though I slightly prefer the inline "if () {" style, I can offer some arguments against it.</div><div><br></div><div>1) it doesn't work well for multi-line conditionals:</div><div><br></div><div> for (std::vector<typeWithLongName>::iterator iter = vec.begin();</div><div> iter != vec.end();</div><div> ++iter) {</div><div> statements;</div><div> }</div><div><br></div><div>versus</div><div><br></div><div><div> for (std::vector<typeWithLongName>::iterator iter = vec.begin();</div><div> iter != vec.end();</div><div> ++iter)</div><div> {</div><div> statements;</div><div> }</div></div><div><br></div><div>2) it's inherently inconsistent. This is demonstrated by the following Java-styled code that actually applies the style consistently:</div><div><br></div><div> int myfunc(int x) {</div><div> if (x == 0) {</div><div> statements;</div><div> }</div><div> }</div><div> </div><div>Most C++ programmers (like myself) think the above is ridiculous, but really, why should a definition block be treated differently from a conditional block?</div><div><br></div><div>In my opinion, putting the brace on the following line is nice because it is a simple, consistent rule that produces easily readable code.</div><div><br></div><div>I'm a fan of compact code, but only when it is compactified according to my own tastes. Otherwise the compactification loses its value ;-)</div><div><br></div><div> - David</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 9, 2015 at 3:29 PM, Brad King <span dir="ltr"><<a href="mailto:brad.king@kitware.com" target="_blank">brad.king@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 9/9/2015 3:41 PM, Brad King wrote:<br>
> if (...) {<br>
> ...<br>
> } else {<br>
> ...<br>
> }<br>
[snip]<br>
> if (...)<br>
> {<br>
> ...<br>
> }<br>
> else<br>
> {<br>
> ...<br>
> }<br>
<br>
</span>There seems to be agreement that either of these is an improvement<br>
but that we should choose now which one to use. I'm sure one can<br>
find endless debates across the web about which one is best. Here<br>
are the main reasons I prefer the former over the latter:<br>
<br>
1. Uses less vertical space. This is important when the content<br>
within the blocks is short.<br>
<br>
2. The start and end of each logical block is aligned horizontally<br>
and can be matched vertically with nothing in the way:<br>
<br>
if (...) {<br>
^ ...<br>
| ...<br>
| ...<br>
| ...<br>
| ...<br>
v ...<br>
} else {<br>
^ ...<br>
| ...<br>
| ...<br>
| ...<br>
| ...<br>
v ...<br>
}<br>
<br>
This is important when the content within the blocks is long.<br>
<br>
3. Distinguishes conditional and unconditional blocks:<br>
<br>
if (...) {<br>
// conditional block<br>
}<br>
<br>
{<br>
// unconditional block<br>
}<br>
<br>
Contrast this to the latter style where both look the same:<br>
<br>
if (...)<br>
{<br>
// conditional block<br>
}<br>
<br>
{<br>
// unconditional block<br>
}<br>
<br>
In the latter style one must read a line above the "{" to see<br>
whether it is a condition. This could be tricky if there is<br>
an unrelated f(...) call there.<br>
<br>
The former style is widely used in many projects and well-supported<br>
by editors.<br>
<div class="HOEnZb"><div class="h5"><br>
-Brad<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtk-developers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtk-developers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtk-developers" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtk-developers</a><br>
<br>
</div></div></blockquote></div><br></div>