Skip to content

Commit

Permalink
Merge pull request betaflight#7310 from mikeller/update_if_brace_policy
Browse files Browse the repository at this point in the history
Updated policy on allowing 'if' without braces.

Agreed 100%
  • Loading branch information
blckmn authored Dec 29, 2018
2 parents a6fabe1 + 3eafbc8 commit f85463b
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions docs/development/CodingStyle.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,7 @@ if (x is true) {
}
```

A single statement after an `if` or an `else` may omit the "unnecessary" braces only when ALL conditional branches have single statements AND you have strong reason to know it will always be that way.
```
if (x is true)
we do y
else
we do z
```

```
if (x is true) {
we do y
...
} else {
we do z
}
```

If in doubt, do not omit such "unnecessary" braces.
(Adding a statement to a branch will break the logic if the braces are forgotten and otherwise make the PR longer).
Omission of "unnecessary" braces in cases where an `if` or `else` block consists only of a single statement is not permissible in any case. These "single statement blocks" are future bugs waiting to happen when more statements are added without enclosing the block in braces.

## Spaces
Use a space after (most) keywords. The notable exceptions are sizeof, typeof, alignof, and __attribute__, which look somewhat like functions (and are usually used with parentheses).
Expand Down

0 comments on commit f85463b

Please sign in to comment.