[llvm-dev] Codifying our Brace rules-

Hubert Tong via llvm-dev llvm-dev at lists.llvm.org
Tue Jun 16 15:54:56 PDT 2020


On Tue, Jun 16, 2020 at 1:23 PM Chris Tetreault via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> I used to agree with the “always put braces unless it fits on a single
> line” camp, but it turns out that it’s really hard to break in a debugger
> on `statement;` if you write it `if (cond) statement;`
>
>
>
> Personally, I’m in the “always put braces” camp. I think the many
> advantages to this approach have been stated by many people in this thread.
> The sole (that I’ve seen mentioned) disadvantage is “clutter”. However, I
> think in practice you learn to ignore the excess braces, especially since
> we write them like this:
>
>
>
> ```
>
> if (foo) {
>
>    bar;
>
> } else if (baz) {
>
>    quux;
>
> }
>
> ```
>
Not that I'm advocating it, but the "omit braces" is most "powerful" when
it removes lines of
```
      }
    }
  }
```

I value the consistent use of braces though. Not only can my editor jump to
the matching brace, but (this might sound paradoxical) it means I can be
less distracted by braces. Without braces, I "focus" on the body and with
braces I "focus" on the delimiters. I find needing to switch back and forth
very distracting. Since we can't omit braces entirely, I'd rather we always
used them.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200616/5de550ec/attachment.html>


More information about the llvm-dev mailing list