mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-21 19:02:25 +00:00
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 <pkrempa@redhat.com> ACKed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
27dfb0280f
commit
9343db59ce
@ -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>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user