I'd like to highlight a few of the new programmer jargons.
1 - I'm thrilled to learn of the "Yoda condition", so now I have something to call this silly way of writing the condition. Can anyone tell me why you'd write the condition this way?
8 - Heisenbugs are something I've been referring to for over 10 years.
20 - I'll need to inform students that "ninja comments" are not acceptable documentation.
1 comment:
Re #1, the reason to do it is because if you slip and type = when you meant == you will get a compile error instead of a logic bug.
The other thing I can think of is if you have a long line, like doing an inline comparison of the result of a function call to a constant, putting the shorter one on the left helps make sure the very existence of the comparison isn't overlooked. (e.g. if you would need to scroll right in your editor to see it) It matters especially in languages where if(foo()) is legal, since that's not the same thing as if(foo() >= 0).
But mostly I think it's the == vs. = thing.
Actually, I make a point never to do an assignment inside a conditional, but typos can occur.
Post a Comment