Assignment in test: OK?

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Sat Sep 15 21:00:23 AEST 1990


As I understand the argument here, Bruce is saying that := vs. == is no
better than = vs. ==, for if C's = had been := instead, people would
have the same confusion. := does have the definite advantage that you
can't mistype it in place of an == so easily, and = does have the
disadvantage that if (a = b) reads well as ``if a equals b''
mathematically.

To some extent, though, Bruce is right: once people think of symbol X as
meaning equality, they'll try writing ``if (a X b)''. The language must
catch this, no matter what X is. The symbol that people use most of the
time in assignments must not return a value. As long as it does, this
problem will remain.

Splitting off := for assignments that do return a value is enough.
People will use = except in situations like a = b := c := d, so they'll
be used to = for equality. When they write if (a = b), the compiler will
catch the mistake.

Bruce, am I right in thinking that =/:=/== would satisfy you?

---Dan



More information about the Comp.lang.c mailing list