== vs =
News system
news at ism780c.UUCP
Wed Feb 3 07:12:16 AEST 1988
In article <1202 at eneevax.UUCP> noise at eneevax.umd.edu.UUCP (Johnson Noise) writes:
> No. I don't understand what the big problem is about = and ==.
>I made that mistake once and only once (it took 15 mins. to find it, but
>I never did it again) when I was still learning the language. If I can
>remember what to use when, I should think most people can.
I decided to find out about the = and == problem by looking at an actual
program written in C. I counted the number of assignment and equality
operations that appeared in the source text of an experimental compiler that
I have working on. Below are the statistics:
1455 assigns
422 equality compares
197498 total source characters.
Now, if assign required two characters and compare required one, the compiler
would have 1033 more characters in its source representation. I am a very
slow typist (80 chars/min). Even so, having a two character symbol for
assignment operator would have added only about 13 minutes to the total
development effort for the compiler.
On the other hand, I once received a bug report that was eventually traced to
a single = appearing in in a comparison. The program in error was a C
compiler! This error caused the compiler to generate a bad code sequence for
certain obscure cases (one of the cases appeared in the FORTRAN compiler that
was written in C). I leave it to you to guess the cost finding the bug,
correcting the C compiler, recompiling every program in the system that had
been developed with the compiler, and distributing a corrected system.
My conclusion: if = had been chosen for the equality operator and any two
character symbol (e.g. ::) had been chosen for the assignment operator, the
cost of developing a program in C would be less even though the character
count in a program might be 0.5% greater.
Marv Rubinstein -- Interactive Systems
More information about the Comp.lang.c
mailing list