Recently, I have noticed the style of some programmers who write "if" statements back. That is, in the test, they first set a constant value, and then the variable that they test the second. So, for example, they write:
bar = foo(); if (MY_CONSTANT == bar) { /* then do something */ }
For me, this makes the code somewhat difficult to read. Since we are really talking about testing the value of the variable "bar", and not all the variables that are equal to "MY_CONSTANT", I always put this variable in the first place. This is a kind of unspoken grammar.
In any case, I see that some programmers ALWAYS do this in the reverse order. In addition, I only noticed this in the last few years. I have been programming in C for over 25 years, and I have not seen this until, say, the last 4 years or so. So my question is:
Is there a reason people do this, and if so, what is it? Is this a generally accepted standard in some languages or projects, or is it taught at some universities? or is it just a few people trying to be different?
source share