Joe Wright wrote:
I write C as I say it. 'If var is 4' is written..
if (var == 4)
I never confuse == and = in these expressions. If I did, either the
compiler will tell me or the test results of the program will.
for (i = 0; i < N; ++i)
Again I say it "increment i" and therefore '++i'.
And you never confuse ++i and i++ in these expressions, because the
compiler or the results will tell you...
Oh, and how do you pronounce "i |= 0x80", by the way? It's either going
to be a circumscription or something that's not English. I "say" this as
"i or-is oh ex eighty", but I don't assign any significance to this --
I'm just reading the symbols. If I were going from English to code, I'd
probably say "set the eighth/high/sign bit of i", depending on i.
"Increment i" does not have the unique translation "++i". Saying that
this is "the way you say it" doesn't mean anything more than "I just
prefer ++i". This "I write it as I say it" argument just muddies the
waters; it's no more or less arbitrary than anything.
The reason most of us don't write (4 == var) regardless of safety is
because it's just not written that way outside C. Open any textbook on
mathematics, sit in any class where equations are written down, and
you'll find that equalities are never written with a constant on the
left hand side and a variable on the right. That, in turn, is a result
of left-to-right writing in English, and the way equations are typically
solved. How we say it has little to do with it.
I've said "increment i" to "i = i + 1", not "i becomes equal to the old
value of i plus one" or suchlike. Of course I'd never write "increment
i" as "i = i + 1" in C, but whether I'll use ++i or i++ depends on the
expression.
If either will do, I'll use ++i, because this is what I'm used to from
(irony) C++. Of course I have no trouble reading any of these
expressions in an abstract sense, and nobody should. And if I can avoid
it, I won't try to express them in English either. English sucks for
writing programs in, though it's excellent at pseudocode.
S.