<div dir="ltr"><div>I'm with Matt on this one. I much prefer the approach of ALWAYS use braces for ifs and for loops, even if they're not needed, for basically the same reasons as he put. The number of times I've added a statement inside an if without braces and forget to add them is annoyingly high, especially as it's not always an obvious error upfront. Similarly, being involved in a downstream codebase with several private patches, having to sometimes add the braces makes merges all the harder and sometimes more dangerous.</div><div><br></div><div>I doubt we're going to get the policy changed from "don't include unnecessary braces for trivial statements" but if there's any style that adds them in more places, I'm up for that.</div><div><br></div><div>James<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 15 Jun 2020 at 20:56, Matt Arsenault via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><br><div><br><blockquote type="cite"><div>On Jun 15, 2020, at 15:46, Keane, Erich via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">Hi all-<u></u><u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">A few weeks ago I noticed that our “omit braces with single line blocks” rule wasn’t written down!  Additionally, as a group on IRC and in review, noticed that the enforcement of this rule has been extremely inconsistent.  We made a first run at codifying our existing practice here:<span> </span><a href="https://reviews.llvm.org/D80947" style="color:rgb(149,79,114);text-decoration:underline" target="_blank">https://reviews.llvm.org/D80947</a>, which was then committed after significant time on llvm-commits.<u></u><u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">I would like to encourage the list via discussion and further reviews/commits to come to a consensus on what we actually MEAN by this rule.  For example, a recent comment points out that :<u></u><u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">If (cond)<u></u><u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">  Stmt;<u></u><u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">else if (cond)<u></u><u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">  Stmt;<u></u><u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">else {<u></u><u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">  Stmt;<u></u><u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">  Stmt;<u></u><u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">}<u></u><u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><u></u> <u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">Should require braces on all of the conditions!  However, we are extraordinarily inconsistent here.  My wish is for us to become more consistent, so I would like us to use this thread to organize our collective thoughts on figuring out what the rule actually SHOULD be, and organizing a handful of commits to the coding standard to make sure it says what we mean.<u></u><u></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><br>Thanks,<br>Erich<u></u><u></u></div></div></div></blockquote><br></div><div><br></div><div>I think braces should be added in all contexts, and the more contexts the better. It eliminates any inconsistency or attempt to contextually interpret rules. It also reduces merge conflicts, since something eventually something will probably be added inside any control flow statement. I’ve suffered through many painful merges trying to find where the braces went wrong, usually due to switch statements. The sometimes-braces-sometimes-not combined with the lack of indentation for switch cases leads to way more time figuring out braces than should be necessary.</div><div><br></div><div>-Matt</div></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>