One more point regarding = and == (more flamage)

David A Keldsen dak at sq.sq.com
Sun Mar 31 08:45:51 AEST 1991


I wrote:
>>I agree with the principle, but I disagree that it applies here.  The 
>>programmer must balance clarity-by-standard-idiom and clarity-by-
>>explicitness.

>>From K&R1 (p. 101):
>>        ...
>>        while (*s++ = *t++)
>>        ...

>>"Although this may seem cryptic at first sight, the notational convenience
>>is considerable, and the idiom should be mastered, if for no other reason
>>than that you will see it frequently in C programs."

s64421 at zeus.usq.EDU.AU (house ron) writes:
>Of course, K&R are not infallible.  Let's argue on logic and evidence
>rather than on quotes from AUTHORITY.

Seems to me that there is a great deal of evidence there.  You *will*
see this construct frequently if you are looking at other people's code.

And the line which you did *not* include, which was my commentary on the
quote:

>>I find the idiomatic usage to be clearer, because it is easier to recognize.

is hardly an argument from authority.  I find the use of the idiom
clearer, when it is *simple* and *concise*.  When the algorithm departs
from the idiom, *then* use explicit tests!

In another article, Steve Summit writes:

> I'm sure that many of us who recommend explicit tests are aware
> of the cited example in K&R.  Note that _use_ of the idiom is not
> condoned, other than obliquely through the undefined concept
> "notational convenience."

As I've emphasized above, I think that explicit tests are a *very*
good idea when the code isn't simple and clear.  However, I find that
that "always use explicit tests" sometimes leads to unclear code,
because it is no longer concise, and I have to figure out, "now,
why is the writer emphasizing the comparison?  What is tricky here?"

Consider the same argument for the increment operator.  Increment is
useful (IMHO) because it makes the use of a common programming idiom
*very* clear.

> K&R1 is one of the best programming texts it has ever been my
> pleasure to learn from, but it is not perfect.  I have precisely
> one real complaint with it, namely the above-quoted example.
> Mere mention in K&R does not automatically render a concept
> inviolate; we're all allowed to think about these things for
> ourselves.

Absolutely.

> Clearly, though, this is a religious argument.

Yes, it's certainly about difficult to dispute preferences.  Shall we
discuss the One True Bracing Style? ;-)

Dak
-- 
David A. 'Dak' Keldsen of SoftQuad, Inc. email: dak at sq.com  phone: 416-963-8337
"You can draw something besides tigers, can't you?"
"Sure, leopards, pumas, ocelots..
..you name it." -- Calvin and Hobbes



More information about the Comp.lang.c mailing list