summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-06-25 09:59:24 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-06-25 10:56:15 +0200
commitb5bd7a29f99b776b73899fe0e42c426de0f859a8 (patch)
tree72062deb27ae29e35675066a8f9c513f9b13d948
parentsystemd-nspawn(1): update example section (diff)
downloadsystemd-b5bd7a29f99b776b73899fe0e42c426de0f859a8.tar.xz
systemd-b5bd7a29f99b776b73899fe0e42c426de0f859a8.zip
some CODING_STYLE additions
-rw-r--r--docs/CODING_STYLE.md13
1 files changed, 13 insertions, 0 deletions
diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md
index d945f8cdbe..517bd2b41d 100644
--- a/docs/CODING_STYLE.md
+++ b/docs/CODING_STYLE.md
@@ -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