diff --git a/doc/contributing/source/coding-style.rst b/doc/contributing/source/coding-style.rst index 64b9a3a71..734409be0 100644 --- a/doc/contributing/source/coding-style.rst +++ b/doc/contributing/source/coding-style.rst @@ -1099,6 +1099,53 @@ can be rewritten as: n += 3; return n; +Boolean Simplifications +======================= + +In order to increase readability and performance, avoid unnecessarily complex boolean +expressions in if statements and variable declarations. + +For instance, the following code: + + .. sourcecode:: cpp + + bool IsPositive(int n) + { + if (n > 0) + { + return true; + } + else + { + return false; + } + } + + void ProcessNumber(int n) + { + if (IsPositive(n) == true) + { + ... + } + } + +can be rewritten as: + + .. sourcecode:: cpp + + bool IsPositive(int n) + { + return n > 0; + } + + void ProcessNumber(int n) + { + if (IsPositive(n)) + { + ... + } + } + Smart pointer boolean comparisons =================================