From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDFHu-0007sB-Ni for qemu-devel@nongnu.org; Fri, 01 Aug 2014 12:02:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XDFHp-0002EU-Ay for qemu-devel@nongnu.org; Fri, 01 Aug 2014 12:02:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6687) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDFHp-0002EM-3f for qemu-devel@nongnu.org; Fri, 01 Aug 2014 12:02:29 -0400 Message-ID: <53DBB9D8.50707@redhat.com> Date: Fri, 01 Aug 2014 10:01:28 -0600 From: Eric Blake MIME-Version: 1.0 References: <1406879176-4008-1-git-send-email-arei.gonglei@huawei.com> <1406879176-4008-2-git-send-email-arei.gonglei@huawei.com> In-Reply-To: <1406879176-4008-2-git-send-email-arei.gonglei@huawei.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Sh1b85SXPnktp2tfR3RWAaKiUDVAJWc51" Subject: Re: [Qemu-devel] [PATCH v3 1/8] CODING_STYLE: Section about conditional statement List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: arei.gonglei@huawei.com, qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, weidong.huang@huawei.com, stefanha@redhat.com, mst@redhat.com, marcel.a@redhat.com, luonengjun@huawei.com, armbru@redhat.com, lcapitulino@redhat.com, av1474@comtv.ru, kraxel@redhat.com, aliguori@amazon.com, imammedo@redhat.com, dmitry@daynix.com, pbonzini@redhat.com, peter.huangpeng@huawei.com, afaerber@suse.de, dgilbert@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --Sh1b85SXPnktp2tfR3RWAaKiUDVAJWc51 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 08/01/2014 01:46 AM, arei.gonglei@huawei.com wrote: > From: Gonglei >=20 > Yoda conditions lack readability, and QEMU has a > strict compiler configuration for checking a common > mistake like "if (dev =3D NULL)". Make it a written rule. >=20 > Signed-off-by: Gonglei > --- > CODING_STYLE | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) >=20 > diff --git a/CODING_STYLE b/CODING_STYLE > index 4280945..b08bfb4 100644 > --- a/CODING_STYLE > +++ b/CODING_STYLE > @@ -91,3 +91,17 @@ Mixed declarations (interleaving statements and decl= arations within blocks) > are not allowed; declarations should be at the beginning of blocks. I= n 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 =3D=3D 0) { > + /* Reads like: "If a is equal to 0" */ I actually tend to read it as 'if a equals 0'. > + do_something(); > +} > + > +Rationale: Yoda conditions (as in 'if (0 =3D=3D a)') are awkward to re= ad. I know this is my suggested text, but now that I'm re-reading it, I'd recommend s/0/1/ in all three places, since comparison to 0 is one of those special cases where '!a' is faster to write than 'a =3D=3D 0'. > +Besides, good compilers already warn users when '=3D=3D' is mis-typed = as '=3D', > +even when the constant is on the right. With those changes, Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --Sh1b85SXPnktp2tfR3RWAaKiUDVAJWc51 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg iQEcBAEBCAAGBQJT27nYAAoJEKeha0olJ0NqkGQH/0i1BWeAZnyY70mU86sIsiKS lIPinzNZ+iIUgByFY5vdMWEATKDDuQbBA+ihYGyJsGQHIgHetxfZKFYTryOrlMcX f5ar72NDcTSTV3Oxi3hXvARDabyb0a/8KTG2CvNQo0DziUfmbbmFRXTBCQSpInTj TqYpF0JEb4ZdTJTpsweZ0qjWupT5HESCz8M7mN3aq0ap9TtIChfl37gfySailKzj Qe5PIzFs0PA/Th4TDjF43Gc7PaP9kZDmuLDHX5en7pjPv7mZmIb1xDxD3eF5WgcY 1yaS7oN98Y7NTdxb7i9887JmW2ABv2q0F7W3+INBoCUrHcMb71nXjEE1SaOlxKw= =ETtL -----END PGP SIGNATURE----- --Sh1b85SXPnktp2tfR3RWAaKiUDVAJWc51--