Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't think learning this is worth it. Using this will not always warn you( complicated expression or variables ) and you still might miss something.

+EDIT: In those occasions when you actually compare to a integer, the expression is so simple that you immediately understand the whole line. In case of an actual typo the compiler will warn you, and the inversion is not needed. Nowadays, there is simply no excuse for a ignored or missed( bad compiler ) warning.

Assignment in an If statement must produce a warning!



Don't understand? If the constant is on the left, then forgetting one of the equals signs will always be an error.


Yes but I think he is saying that if the left/what you compare to is not a constant then it will not warn you (if the type agrees, as it should anyway for a comparison).


If the left is a function call, it will still error out because you can't assign to it.

If you're doing

    if (var1 == var2)
then yoda expressions won't save you, however.


Also, in C++ you can assign to the return value of a function returning a reference.


The word learning in this context doesn't mean understanding this simple trick, which any newbie should grasp immediately.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: