[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 1/8] CODING_STYLE: Section about conditional stat
From: |
arei.gonglei |
Subject: |
[Qemu-devel] [PATCH v4 1/8] CODING_STYLE: Section about conditional statement |
Date: |
Mon, 4 Aug 2014 17:19:45 +0800 |
From: Gonglei <address@hidden>
Yoda conditions lack readability, and QEMU has a
strict compiler configuration for checking a common
mistake like "if (dev = NULL)". Make it a written rule.
Signed-off-by: Gonglei <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
CODING_STYLE | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/CODING_STYLE b/CODING_STYLE
index 4280945..d46cfa5 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -91,3 +91,17 @@ 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 statements
+
+When comparing a variable for (in)equality with a constant, list the
+constant on the right, as in:
+
+if (a == 1) {
+ /* Reads like: "If a equals 1" */
+ do_something();
+}
+
+Rationale: Yoda conditions (as in 'if (1 == a)') are awkward to read.
+Besides, good compilers already warn users when '==' is mis-typed as '=',
+even when the constant is on the right.
--
1.7.12.4
- [Qemu-devel] [PATCH v4 0/8] don't use Yoda conditions, arei.gonglei, 2014/08/04
- [Qemu-devel] [PATCH v4 7/8] vl: don't use 'Yoda conditions', arei.gonglei, 2014/08/04
- [Qemu-devel] [PATCH v4 8/8] vmxnet3: don't use 'Yoda conditions', arei.gonglei, 2014/08/04
- [Qemu-devel] [PATCH v4 3/8] audio: don't use 'Yoda conditions', arei.gonglei, 2014/08/04
- [Qemu-devel] [PATCH v4 5/8] don't use 'Yoda conditions', arei.gonglei, 2014/08/04
- [Qemu-devel] [PATCH v4 2/8] usb: don't use 'Yoda conditions', arei.gonglei, 2014/08/04
- [Qemu-devel] [PATCH v4 6/8] spice: don't use 'Yoda conditions', arei.gonglei, 2014/08/04
- [Qemu-devel] [PATCH v4 4/8] isa-bus: don't use 'Yoda conditions', arei.gonglei, 2014/08/04
- [Qemu-devel] [PATCH v4 1/8] CODING_STYLE: Section about conditional statement,
arei.gonglei <=
- Re: [Qemu-devel] [PATCH v4 0/8] don't use Yoda conditions, Eric Blake, 2014/08/05