From: Peter Krempa Date: Thu, 9 May 2019 10:27:25 +0000 (+0200) Subject: docs: hacking: Discourage use of the ternary operator and ban it's abuse X-Git-Tag: v5.4.0-rc1~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9343db59ce49138907545d6925d99c122cfe8139;p=thirdparty%2Flibvirt.git docs: hacking: Discourage use of the ternary operator and ban it's abuse Forbid breaking lines inside the two branches of the ternary operator and nesting them. Using it in these instances does not help readability. Signed-off-by: Peter Krempa ACKed-by: Eric Blake --- diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 1f82c668e5..859e33a874 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -847,6 +847,17 @@ BAD: if (!nfoos) if (nfoos) +

New code should avoid the ternary operator as much as possible. + Specifically it must never span more than one line or nest: +

+
+BAD:
+    char *foo = baz ?
+                virDoSomethingReallyComplex(driver, vm, something, baz->foo) :
+                NULL;
+
+    char *foo = bar ? bar->baz ? bar->baz->foo : "nobaz" : "nobar";
+

Preprocessor