coding convention: break brace after multiline control statement#22205
Draft
maribu wants to merge 3 commits intoRIOT-OS:masterfrom
Draft
coding convention: break brace after multiline control statement#22205maribu wants to merge 3 commits intoRIOT-OS:masterfrom
maribu wants to merge 3 commits intoRIOT-OS:masterfrom
Conversation
Adding a line break before the `{` after a multiline if statement helps
readability a lot, as telling apart where the function body starts and
where the if conditions ends becomes trivial from the indent only.
We current do not wrap the brace after a control statement ever. This
changes the behavior to still not break the line before the brace by
default, but do break it on multiline statements.
E.g. before:
```c
if (boolean_expr1) {
do_something();
}
if (boolean_expr2 &&
boolean_expr3) {
do_something();
}
```
With this change this now becomes:
```c
if (boolean_expr1) {
do_something();
}
if (boolean_expr2 &&
boolean_expr3)
{
do_something();
}
```
Note that the behavior before suffered from poor readability of the
code structure, as the indent does not make it obvious where the
condition of the if statements ends and where the function body starts.
With this change, the code becomes one line longer for the rare long
boolean expressions, but the code structure is much easier to spot.
crasbe
reviewed
Apr 21, 2026
…tmts Co-authored-by: crasbe <crasbe@gmail.com>
Contributor
|
WTF why worsen (more special handling) a already ugly coding style is the another well known project that does that? we could instead just remove the requirement to have the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution description
We current do not wrap the brace after a control statement ever. This changes the behavior to still not break the line before the brace by default, but do break it on multiline statements.
E.g. before:
With this change this now becomes:
Note that the behavior before suffered from poor readability of the code structure, as the indent does not make it obvious where the condition of the if statements ends and where the function body starts. With this change, the code becomes one line longer for the rare long boolean expressions, but the code structure is much easier to spot.
Testing procedure
clang-formatwill not remove the line break in front of{if and only if the condition is split over multiple lines.Sadly,
clang-formatwill not add the line breaks ever unless a maximum line width is specified. Butclang-formatis relatively heavy-handing in filling lines up until the column limit, which doesn't match with the soft and hard column limit defined in our coding conventions. Hence, reflowing content has been disabled in clang-format so far.Issues/PRs references
None
Declaration of AI-Tools / LLMs usage:
AI-Tools / LLMs that were used are:
PR State
clang-formatto match the updated coding conventionuncrustifyto match the updated coding convention