Skip to content

Commit

Permalink
Merge pull request betaflight#7312 from mikeller/amend_parentheses_rule
Browse files Browse the repository at this point in the history
Amended rule to stipulate minimal use of parentheses.
  • Loading branch information
mikeller authored Jan 12, 2019
2 parents 9b43b30 + af0a3ad commit 10ae62e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions docs/development/CodingStyle.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,15 @@ Same for multiple `return` from a function and multiple `break` inside a `case`.
In general, they reduce readability and maintainability.
In rare cases such constructs can be justified but only when you have considered and understood the alternatives and still have a strong reason.

Use parentheses around each group in logical and mathematical statements,
rather than relying on the implicit logic and operator priority.
The compiler knows what it’s doing but it should be easy for people too.
In expressions, parentheses should only be used where they are required, i.e. where operator precedence will not evaluate in the right order, or where a compiler warning is triggered without parentheses. This brings all expressions into a canonical form, and avoids the problem of different developers having different ideas of what 'easy to read' expressions are.

One exception to this rule is the ternary conditional operator

```
pidStabilisationEnabled = (pidControllerState == PID_STABILISATION_ON) ? true : false
```

Here, the condition shall be enclosed in braces, to make the ternary operator easier to spot when reading left to right.

# Includes

Expand Down

0 comments on commit 10ae62e

Please sign in to comment.