K
Kenny McCormack
However this is an incomplete solution (you don't always have a non-lvalue
available) that results in less readable and less consistent code. Many
compilers will diagnose this given suitable options and there are other
"lint" tools available which will do so. This is much more relaible than
source tricks like that above and is a much better approach.
Lawrence
Absolutely, switching the left and right sides of an equality test as
it is conventionally written makes the expression less readable [until
the pattern becomes familiar]. The more readable the code, the more
likely its errors will be overlooked. "Readable" text describes text
that fits a familiar pattern, and which the brain can read faster
because it can skip many of the words by filling in their most likely
form and meaning. In this case an assignment expression can "read" like
an equality test, so the mistake can go undetected.[/QUOTE]
Very interesting. (Rest of very eloquent defense of your very clearly
non-mainstream position - deleted only to save space)
Mainstream thought today is that source code should be *readable* by humans
and *understandable* by computers. This is so that you can spend less on
humans.
My $.02: People who maintain the converse of your (Greg's) position should
not be programming in C. (*)
(*) Read this carefully - this is not a typo.
P.S. If you really care about this "problem" (which hasn't been a problem
for me since about the 3rd week of my time as a C programmer), just do:
#define EQUALS ==
and use that for equality tests.
P.P.S. This discussion is antique anyway, since every (*) C compiler since
about 1989 has issued a warning about this (yes, sometimes you do have to
find the right compiler option for it)
(*) Don't bother writing in with obscure exceptions to this generalization.