[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 1/8] CODING_STYLE: Section about conditional stat
From: |
arei.gonglei |
Subject: |
[Qemu-devel] [PATCH v2 1/8] CODING_STYLE: Section about conditional statement |
Date: |
Fri, 1 Aug 2014 10:32:38 +0800 |
From: Gonglei <address@hidden>
Yoda conidtions lack of readability, and QEMU have a
strict compiler configuration for checking a common
mistake like "if (dev = NULL)". Make it a written rule.
Signed-off-by: Gonglei <address@hidden>
---
CODING_STYLE | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/CODING_STYLE b/CODING_STYLE
index 4280945..11a79d4 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -91,3 +91,22 @@ Mixed declarations (interleaving statements and declarations
within blocks)
are not allowed; declarations should be at the beginning of blocks. In other
words, the code should not generate warnings if using GCC's
-Wdeclaration-after-statement option.
+
+6. Conditional statement
+
+Please don't use Yoda conditions because of lack of readability. Furthermore,
+it is not the QEMU idiomatic coding style. Example:
+
+Usually a conditional statement in QEMU would be written as:
+if (a == 0) {
+ /* Reads like: "If a is equal to 0..." */
+ do_something();
+}
+
+Yoda conditions describe the same expression, but reversed:
+if (0 == a) {
+ /* Reads like: "If 0 equals to a" */
+ do_something();
+}
+
+The constant is listed first, then the variable being compared to.
--
1.7.12.4
[Qemu-devel] [PATCH v2 1/8] CODING_STYLE: Section about conditional statement,
arei.gonglei <=
[Qemu-devel] [PATCH v2 6/8] spice: a trivial code change for more idiomatic writing style, arei.gonglei, 2014/07/31
[Qemu-devel] [PATCH v2 7/8] vl: a trivial code change for more idiomatic writing style, arei.gonglei, 2014/07/31
[Qemu-devel] [PATCH v2 5/8] a trivial code change for more idiomatic writing style, arei.gonglei, 2014/07/31
[Qemu-devel] [PATCH v2 4/8] isa-bus: a trivial code change for more idiomatic writing style, arei.gonglei, 2014/07/31
Re: [Qemu-devel] [PATCH v2 for-2.2 0/8] about Yoda conditions, Eric Blake, 2014/07/31