How do you explain the obvious?

friedman at uiucdcsb.cs.uiuc.edu friedman at uiucdcsb.cs.uiuc.edu
Fri Apr 29 00:22:00 AEST 1988


Jim Harkins (jlh at loral.UUCP) writes:

> I seem to have inherited a program that is, ahem, not in good shape.
> For example, there was a '#define OK 0' at the top of the code, and
> some of the routines actually used it.  BUT, in addition to OK, it used 0,
> FALSE, and NULL used interchangeably!  I couldn't believe it!
> I mentioned that this was not a good thing to do and the response was "Why
> not?  I know it's 0 because I set it to 0!".  I'm stumped.  To me the
> answer is so obvious I can't think of anything better than "because".
> So what do I tell this person?

Tell the person:  (1) It's bad because it's confusing to read due to the
inconsistency.  You aren't writing just for the compiler's benefit, but
for the humans who come after you and have to read and understand the
program and modify it.  (2) It's bad because, in the rare circumstance
that one wanted to change the value of "OK", one might reasonably expect
to change the one #define and presume that would get the job done.  The
inconsistent usage would destroy that reasonable expectation.

       		H. George Friedman, Jr.
       		Department of Computer Science
       		University of Illinois at Urbana-Champaign
       		1304 West Springfield Avenue
       		Urbana, Illinois  61801

       		USENET:	...!{pur-ee,ihnp4,convex}!uiucdcs!friedman
       		CSNET:	friedman at a.cs.uiuc.edu
       		ARPA:	friedman at a.cs.uiuc.edu



More information about the Comp.lang.c mailing list