E
Ersek, Laszlo
Keith Thompson said:Would you even consider writing '7 == x' rather than 'x == 7'
if C's equality and comparison operators were more distinct?
For example, consider a hypothetical C-like language in which the
equality operator is spelled "=" and the assignment operator is
"<-", and "==" is a syntax error. (Yes, that would quietly break
"x<-1"; let's ignore that.)
In such a language, would you ever write "if (7 = x)" in preference
to "if (x = 7)"? If so, why?
No, I would not have picked up the "7 == x" style in that case.
For example, Pascal has := for assignment and = for equality (IIRC ). Even
in C, I started out with "x == 7". I was occasionally bitten by
"if (x = 7)" typos. Not very frequently, and most of the time caught by
compiler warnings. However, on some forum somebody brought up "7 == x"
explicitly, and after giving the idea my unrelenting attention for a
minute or two, I liked it so much that I trained myself to it.
Cheers,
lacos