[llvm-dev] Codifying our Brace rules-
Matt Arsenault via llvm-dev
llvm-dev at lists.llvm.org
Mon Jun 15 12:56:09 PDT 2020
> On Jun 15, 2020, at 15:46, Keane, Erich via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>
> Hi all-
>
> 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: https://reviews.llvm.org/D80947 <https://reviews.llvm.org/D80947>, which was then committed after significant time on llvm-commits.
>
> 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 :
>
> If (cond)
> Stmt;
> else if (cond)
> Stmt;
> else {
> Stmt;
> Stmt;
> }
>
> 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.
>
> Thanks,
> Erich
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.
-Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200615/3018cb00/attachment.html>
More information about the llvm-dev
mailing list