[llvm-dev] Codifying our Brace rules-

Momchil Velikov via llvm-dev llvm-dev at lists.llvm.org
Tue Jun 16 01:35:07 PDT 2020


My 2 pennies is braces add unnecessary clutter and impair readability when
used on a *single-line* statement. I count comments, that are on their
own line as statement(s).

For example:

BAD:

if (cond)
  // Comment
  foo();


GOOD:
if (cond) {
  // Comment
  foo();
}

BAD:
if (cond) {
  foo(); // Comment
}

GOOD:
if (cond)
  foo(); // Comment

BAD:
if (cond)
  for(;;)
    foo()


GOOD:
if (cond) {
  for(;;)
    foo()
}

Some new-ish languages like Go and Swift went to always require braces.
However, I've never
seen a study, which concluded that always requiring braces has an overall
positive effect
on code quality.

Is there such a thing?

Lacking that, it becomes a matter of personal taste and preference and
anecdotal evidence
in favour of one or the other style. Speaking of which, as I constantly run
clang-format
on the blocks of code, that I currently modify, I don't think I've ever
misplaced a statement.

~chill

-- 
Compiler scrub, Arm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200616/44ad6328/attachment.html>


More information about the llvm-dev mailing list