From 82e999e58975fdff46f013b587e23959ec245ab4 Mon Sep 17 00:00:00 2001 From: mikeller Date: Sun, 30 Dec 2018 00:32:26 +1300 Subject: [PATCH 1/2] Amended rule to stipulate minimal use of parentheses. --- docs/development/CodingStyle.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/development/CodingStyle.md b/docs/development/CodingStyle.md index 912cd109c6..e980b6eed8 100644 --- a/docs/development/CodingStyle.md +++ b/docs/development/CodingStyle.md @@ -270,9 +270,7 @@ 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. # Includes All files must include their own dependencies and not rely on includes from the included files or that some other file was included first. From af0a3ad58b55a9755d32417a48c87b0d2cd5158c Mon Sep 17 00:00:00 2001 From: mikeller Date: Sun, 30 Dec 2018 10:15:12 +1300 Subject: [PATCH 2/2] Added exception for ternary conditional operator. --- docs/development/CodingStyle.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/development/CodingStyle.md b/docs/development/CodingStyle.md index e980b6eed8..12ee3e794a 100644 --- a/docs/development/CodingStyle.md +++ b/docs/development/CodingStyle.md @@ -272,6 +272,14 @@ In rare cases such constructs can be justified but only when you have considered 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 All files must include their own dependencies and not rely on includes from the included files or that some other file was included first.