From 9343db59ce49138907545d6925d99c122cfe8139 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 9 May 2019 12:27:25 +0200 Subject: [PATCH] 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 --- docs/hacking.html.in | 11 +++++++++++ 1 file changed, 11 insertions(+) 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

-- GitLab