From owner-freebsd-hackers@FreeBSD.ORG Tue May 11 20:33:28 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C2DD4106564A for ; Tue, 11 May 2010 20:33:28 +0000 (UTC) (envelope-from max@love2party.net) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.187]) by mx1.freebsd.org (Postfix) with ESMTP id 5579A8FC15 for ; Tue, 11 May 2010 20:33:28 +0000 (UTC) Received: from vampire.homelinux.org (dslb-088-066-053-135.pools.arcor-ip.net [88.66.53.135]) by mrelayeu.kundenserver.de (node=mrbap2) with ESMTP (Nemesis) id 0MZ776-1NtIIU3spo-00Ln8a; Tue, 11 May 2010 22:33:27 +0200 Received: (qmail 9267 invoked from network); 11 May 2010 20:33:26 -0000 Received: from f8x64.laiers.local (192.168.4.188) by ns1.laiers.local with SMTP; 11 May 2010 20:33:26 -0000 From: Max Laier Organization: FreeBSD To: freebsd-hackers@freebsd.org Date: Tue, 11 May 2010 22:33:24 +0200 User-Agent: KMail/1.12.4 (FreeBSD/8.0-RELEASE-p2; KDE/4.3.5; amd64; ; ) References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201005112233.24473.max@love2party.net> X-Provags-ID: V01U2FsdGVkX19WfJ9N6/co/WsWZkUZHnyPXXHLIUylS8yGm9A 8dfvd01dV3Ngm+5qnHtHZRANr63R2BDjnjkQM9K2+rQV6QKYM+ e6/GKv8+vr9waZ6Az/qfA== Cc: Eitan Adler 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 List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 May 2010 20:33:28 -0000 On Tuesday 11 May 2010 21:36:11 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) > > While this is almost always found in testing sometimes thing can slip > through and writing it using the former method will generate a compiler > warning. With proper -W flags, "if (var = const)" also yields a warning: warning: suggest parentheses around assignment used as truth value and style already tells you to avoid unnecessary parentheses. Chaning style(9) in such a fundamental way almost, always isn't a good idea. It's simply unrealistic to change all current code to comply and the difference between old and new code will just add to the confusion. Best, Max