From patchwork Fri Aug 15 15:14:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 380274 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D6D17140086 for ; Sat, 16 Aug 2014 01:16:24 +1000 (EST) Received: from localhost ([::1]:59904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIJEs-0002Ek-MC for incoming@patchwork.ozlabs.org; Fri, 15 Aug 2014 11:16:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIJDz-0000v5-Sf for qemu-devel@nongnu.org; Fri, 15 Aug 2014 11:15:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIJDn-0005ax-Qx for qemu-devel@nongnu.org; Fri, 15 Aug 2014 11:15:27 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:48494) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIJDn-0005aW-J5; Fri, 15 Aug 2014 11:15:15 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 0033E42F58; Fri, 15 Aug 2014 19:15:14 +0400 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.corpit.ru (Postfix) with SMTP id E112C6E0; Fri, 15 Aug 2014 19:15:13 +0400 (MSK) Received: (nullmailer pid 17914 invoked by uid 1000); Fri, 15 Aug 2014 15:15:13 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Date: Fri, 15 Aug 2014 19:14:57 +0400 Message-Id: <1408115711-17836-7-git-send-email-mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1408115711-17836-1-git-send-email-mjt@msgid.tls.msk.ru> References: <1408115711-17836-1-git-send-email-mjt@msgid.tls.msk.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 86.62.121.231 Cc: qemu-trivial@nongnu.org, Gonglei , Michael Tokarev Subject: [Qemu-devel] [PULL 06/20] CODING_STYLE: Section about conditional statement X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Gonglei 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 Reviewed-by: Eric Blake Signed-off-by: Michael Tokarev --- 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.