some CODING_STYLE additions
authorLennart Poettering <lennart@poettering.net>
Tue, 25 Jun 2019 07:59:24 +0000 (09:59 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 25 Jun 2019 08:56:15 +0000 (10:56 +0200)
docs/CODING_STYLE.md

index d945f8c..517bd2b 100644 (file)
@@ -201,6 +201,19 @@ title: Coding Style
   array. In that case use STRLEN, which evaluates to a static constant and
   doesn't force the compiler to create a VLA.
 
+- Please use C's downgrade-to-bool feature only for expressions that are
+  actually booleans (or "boolean-like"), and not for variables that are really
+  numeric. Specifically, if you have an `int b` and it's only used in a boolean
+  sense, by all means check its state with `if (b) …` — but if `b` can actually
+  have more than two semantic values, and you want to compare for non-zero,
+  then please write that explicity with `if (b != 0) …`. This helps readability
+  as the value range and semantical behaviour is directly clear from the
+  condition check. As a special addition: when dealing with pointers which you
+  want to check for non-NULL-ness, you may also use downgrade-to-bool feature.
+
+- Please do not use yoda comparisons, i.e. please prefer the more readable `if
+  (a == 7)` over the less readable `if (7 == a)`.
+
 ## Destructors
 
 - The destructors always deregister the object from the next bigger object, not