Richard Heathfield posted:
If it matters because you expect the constant to be in a certain
position and are surprised when it is not, rest assured that I, too,
expect the constant to be in a certain position and am surprised when it
is not.
Yes, but your expectation to see the constant on the left-hand side of the
equality operator is purely out of habit and conditioning, and nothing to do
with any inherent meaning or understanding. The situation is not like a more
inherent idea like handness, whereby a baby is predisposed to favouring one
hand over another, a predisposition which can't be changed by yanking the
crayon out of their hand and placing it in the other hand. Quite the
contrary, this whole "C==v" business is simply a habit, like writing
"unsigned char" instead of "char unsigned".
The people who favour:
constant == variable
argue that it is less prone to typos. The people who argue:
variable == constant
argue little more than that you can't teach an old dog new tricks.
So, for you, it matters that we write if(v == C), and for me it
matters that we write if(C == v).
I consciously write C==v for the reason cited above. I find it superior. If
I'm reading other people's code however, I don't even pay attention to their
style, I just extract the meaning regardless of whether they write "i++"
instead of "++i", or "char unsigned" instead of "unsigned char", or "int
const *" instead of "const int*". Thankfully my knowledge of the C Standard
allows me to interpret any grammatically correct code, irrespective of
whether it differs from my own grammar usage.
Oh well. If we ever end up working on the same project, I guess we'll
have to come up with a compromise - i.e. a solution that pleases nobody
but which gives everyone the satisfying feeling that the other fellow
didn't get his way either.
I think it would be better to train your mind for dealing with variance,
whether it be hearing someone say "tomAto" instead of "toMAYto", or writing
"v==C" instead of "C==v". The reason you find the latter to be ugly is
because it's horribly alien to you and it's far removed from what you've been
accustomed to for a great deal of time. Don't mask the symptoms, kill the
infection -- there's nothing wrong with "C==v" except your attitude to it,
and so you would be better to get used to it rather than grimacing every time
you encounter it.