proposed change to style(9): require yoda style if statements

Garance A Drosehn gad at
Thu May 13 22:35:25 UTC 2010

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 at
Senior Systems Programmer               or   gad at
Rensselaer Polytechnic Institute;             Troy, NY;  USA

More information about the freebsd-hackers mailing list