Date: Thu, 13 May 2010 17:26:44 -0400 From: Garance A Drosehn <gad@FreeBSD.org> To: Eitan Adler <lists@eitanadler.com>, hackers@FreeBSD.org Subject: Re: proposed change to style(9): require yoda style if statements Message-ID: <p06240808c8121d92f9c6@[128.113.24.47]> In-Reply-To: <AANLkTimCLELSQ9YNZ403_PLhKOQCQTcl9H1bfb1ccRNb@mail.gmail.com> References: <AANLkTimCLELSQ9YNZ403_PLhKOQCQTcl9H1bfb1ccRNb@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?p06240808c8121d92f9c6>