From owner-freebsd-hackers@FreeBSD.ORG Thu May 13 23:16:41 2010 Return-Path: Delivered-To: hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C11C7106566B; Thu, 13 May 2010 23:16:41 +0000 (UTC) (envelope-from delphij@delphij.net) Received: from tarsier.geekcn.org (tarsier.geekcn.org [IPv6:2001:470:a803::1]) by mx1.freebsd.org (Postfix) with ESMTP id 689018FC08; Thu, 13 May 2010 23:16:41 +0000 (UTC) Received: from mail.geekcn.org (tarsier.geekcn.org [211.166.10.233]) by tarsier.geekcn.org (Postfix) with ESMTP id 73198A69E26; Fri, 14 May 2010 07:16:40 +0800 (CST) X-Virus-Scanned: amavisd-new at geekcn.org Received: from tarsier.geekcn.org ([211.166.10.233]) by mail.geekcn.org (mail.geekcn.org [211.166.10.233]) (amavisd-new, port 10024) with LMTP id kdtcUO7z1bAq; Fri, 14 May 2010 07:16:22 +0800 (CST) Received: from delta.delphij.net (drawbridge.ixsystems.com [206.40.55.65]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by tarsier.geekcn.org (Postfix) with ESMTPSA id 194A0A69D3E; Fri, 14 May 2010 07:16:20 +0800 (CST) DomainKey-Signature: a=rsa-sha1; s=default; d=delphij.net; c=nofws; q=dns; h=message-id:date:from:reply-to:organization:user-agent: mime-version:to:cc:subject:references:in-reply-to: x-enigmail-version:openpgp:content-type:content-transfer-encoding; b=Q15MAmm/82GGUZvPDk2y86CS7z2u8FJzb7C+jEK6p34ytN/PZXdANtMGhzvcqsY7P T53v3hXk/0D63DsDCSwdw== Message-ID: <4BEC883F.1060602@delphij.net> Date: Thu, 13 May 2010 16:16:15 -0700 From: Xin LI Organization: The Geek China Organization User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.1.9) Gecko/20100408 Thunderbird/3.0.4 ThunderBrowse/3.2.8.1 MIME-Version: 1.0 To: Garance A Drosehn References: In-Reply-To: X-Enigmail-Version: 1.0.1 OpenPGP: id=3FCA37C1; url=http://www.delphij.net/delphij.asc Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Eitan Adler , hackers@FreeBSD.org Subject: Re: proposed change to style(9): require yoda style if statements X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: d@delphij.net List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 May 2010 23:16:41 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 2010/05/13 14:26, Garance A Drosehn wrote: > At 10:36 PM +0300 5/11/10, Eitan Adler wrote: >> My proposal is simple: >> require that any if statement that compares a constant to a mutable >> variable >> be written as >> if (constant == variable) >> instead of >> if (variable == constant) >> >> this prevents an extremely common programming error >> if (variable = constant) > > > I did this for awhile in my own programming, long enough ago that > there was no cool "yoda" name connected to it. But I found that in > some situations it makes the code harder to read, so I don't do it > as much any more. I don't mind if people do it, but I do not think > it should be an official recommendation in style(9). Or to say it > another way, I'd be annoyed if an otherwise-correct patch was asked > to be rewritten just because the developer used (variable == constant) > instead of (constant == variable). I used to use this style of programming a lot but gave up ~7 years ago when I found that some C++ compiler can be confused in very ugly manner (due to type mismatch), not to mention that using this style sometimes makes the code harder to read. It turns out that modern compilers are more sensitive about this type of mistakes, and, more importantly, making code more readable would usually save debugging time. Cheers, - -- Xin LI http://www.delphij.net/ FreeBSD - The Power to Serve! Live free or die -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (FreeBSD) iQEcBAEBAgAGBQJL7Ig/AAoJEATO+BI/yjfBiQwH/R6nlA5DciXXHfl1XDxDMe81 fnmOCgCAbidKySiwlmKJhsfLuZgKQX/jVqO2Z28X+0cOQVqLw2bZ9hlfyZ306uGy vwYDXzs+E805T+S9UArKe7jJdoeuQajJ7w+Z0eJfCjFBgb9KCW/KTIaPaFJJtvbS azVB0q7tuZGd2xPj6iNmuxteeN1B0aixYNov5cGtSs3anH9rwFPFqJAntN8nRWTm 0W9ocOgi/cNYfNMuapvxSsRv2IJiAe+EpikpRhDJT2ushFnQ1ML4a2Mgld7sz+jn YvYHUi5LAnyl7oIS5hxF7d7ADINmPuKnoBNbgiYoMLpNjsE1thAsXPFv8SWI3qs= =ngfR -----END PGP SIGNATURE-----