From owner-freebsd-hackers@FreeBSD.ORG Thu May 13 22:35:25 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 A7D5B106566B for ; Thu, 13 May 2010 22:35:25 +0000 (UTC) (envelope-from gad@FreeBSD.org) Received: from smtp5.server.rpi.edu (smtp5.server.rpi.edu [128.113.2.225]) by mx1.freebsd.org (Postfix) with ESMTP id 49D928FC14 for ; Thu, 13 May 2010 22:35:25 +0000 (UTC) Received: from [128.113.24.47] (gilead.netel.rpi.edu [128.113.24.47]) by smtp5.server.rpi.edu (8.13.1/8.13.1) with ESMTP id o4DLQjxm011131; Thu, 13 May 2010 17:26:47 -0400 Mime-Version: 1.0 Message-Id: In-Reply-To: References: Date: Thu, 13 May 2010 17:26:44 -0400 To: Eitan Adler , hackers@FreeBSD.org From: Garance A Drosehn Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-Bayes-Prob: 0.0704 (Score 0) X-RPI-SA-Score: 0.10 () [Hold at 20.00] COMBINED_FROM X-CanItPRO-Stream: outgoing X-Canit-Stats-ID: Bayes signature not available X-Scanned-By: CanIt (www . roaringpenguin . com) on 128.113.2.225 Cc: 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: Thu, 13 May 2010 22:35:25 -0000 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). -- Garance Alistair Drosehn = drosehn@rpi.edu Senior Systems Programmer or gad@FreeBSD.org Rensselaer Polytechnic Institute; Troy, NY; USA