]> xenbits.xensource.com Git - libvirt.git/commitdiff
docs: hacking: Discourage use of the ternary operator and ban it's abuse
authorPeter Krempa <pkrempa@redhat.com>
Thu, 9 May 2019 10:27:25 +0000 (12:27 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 22 May 2019 12:46:29 +0000 (14:46 +0200)
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 <pkrempa@redhat.com>
ACKed-by: Eric Blake <eblake@redhat.com>
docs/hacking.html.in

index 1f82c668e52807b32ed20e7a5c4a4f4af37f77ee..859e33a874f2f2d84d9374ecf88370ff4c2a62e0 100644 (file)
@@ -847,6 +847,17 @@ BAD:
     if (!nfoos)
     if (nfoos)
 </pre>
+      <p>New code should avoid the ternary operator as much as possible.
+        Specifically it must never span more than one line or nest:
+      </p>
+<pre>
+BAD:
+    char *foo = baz ?
+                virDoSomethingReallyComplex(driver, vm, something, baz->foo) :
+                NULL;
+
+    char *foo = bar ? bar->baz ? bar->baz->foo : "nobaz" : "nobar";
+</pre>
 
     <h2><a id="preprocessor">Preprocessor</a></h2>