CONTRIBUTING: clarify on the use/lack of curly braces around blocks

This is the style we have ever since. Spell it out. With the difference
that now single line statements may have braces.

Recently we were already sloppy about allowing curly braces for single line
statements. Maybe there was a point in that. Imagine you start with:

    if (condition)
        call(some, parameter);

Afterwards you change the code so that the line becomes too long and
clang-format wraps the line (requiring you to add braces):

    if (condition) {
        call(some,
             call_another_function(hey));
    }

The problem now is that this diff is larger than it would have been, if
you added curly braces from the start. Also, it means you have to go
back and forth to add/remove these braces, as clang-format reformats the
code.

Also, if you have if-else-if blocks, then mixing multi line statements
with single line statements is also cumbersome, because when something
needs to change, the diff is may be larger (and the change more
cumbersome).

So it might be convenient to just always add the braces, and the
documented style now allows for that.
This commit is contained in:
Thomas Haller 2022-01-11 09:59:01 +01:00
parent d5f917e702
commit 9ab22dbc80
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -101,6 +101,9 @@ some details of the style we use:
- GOOD: `#define MY_CONSTANT 42`
- BAD: `static const unsigned myConstant = 42;`
* Always use curly braces for blocks that span multiple lines. For single lines
the braces may be omitted, but are not prohibited.
Additionally, we require to build without compiler warnings for the warnings
that we enable. Also, our language is C11 with some GCC-isms (like typeof(),
expression statements, cleanup attribute). In practice, we support various versions