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

Dominic Fandrey kamikaze at bsdforen.de
Wed May 12 14:40:00 UTC 2010


On 12/05/2010 14:43, Dag-Erling Smørgrav wrote:
> Dominic Fandrey <kamikaze at bsdforen.de> writes:
>> I think the pro-yoda faction actually has more convincing arguments,
> 
> Which ones?  Never seen any beyond the basic "helps avoid accidentally
> typing = instead of ==".  It's bollocks, anyway, because a) for every
> (variable == constant) comparison you have ten (variable == variable)
> comparisons and b) good compilers will warn about bare assignments used
> as conditions.
> 
> The only practical effect of Yoda style is to make code harder to read.

The convincing one applies to Java and C++:
if (constant.equals(object))
instead of
if (object != null && object.equals(constant))
actually looks easier to read.

Though you are right about constants being pretty rare.

> Your .sig is strangely appropriate...

Not my invention, this is a pretty common one, used by many people
on the net. I actually have no idea where it comes from.

-- 
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail? 


More information about the freebsd-hackers mailing list