Cryptic C (YES/NO vs. TRUE/FALSE + other thoughts)

Arnold Robbins arnold at gatech.CSNET
Sat Aug 24 02:57:20 AEST 1985


In article <5884 at utzoo.UUCP>, henry at utzoo.UUCP (Henry Spencer) writes:
> > 	typedef int	bool;
> > 	#define	false	0
> > 	#define	true	1
> 
> It's interesting to note that Kernighan&Plauger use "yes" and "no" rather
> than "true" and "false", and my own reaction is that the code often reads
> better that way.  Now that's something to *really* start a raging debate
> about... :-)
> -- 
> 				Henry Spencer @ U of Toronto Zoology

Well, this can get carried too far.  I have worked with code based on
Software Tools stuff that looks like

	dowrite (file, YES, NO, NO, YES);

Now, can you tell what the heck it is doing? Especially when the code for
dowrite() is 700 lines down in another file? I've often thought that a style
like

#define FORCEWRITE	1
#define NOFORCE		0

#define APPEND		1
#define NOAPPEND	0

	dowrite (file, FORCEWRITE, APPEND, ....);	/* call */

int dowrite (file, force, append,...)	/* actual procedure */
...
{
	if (force)
		....
	if (append)
		....
}

is much clearer than the first style.  This is the kind of thing, if anything,
that "enums" would be most useful for (no flames about how poorly enums are
implemented. I'm talking conceptually here.).  Overall, TRUE or FALSE or YES
or NO doesn't make much difference to me.  However, I much prefer the following

	if (boolean)
		something
and

	boolean = (x && y || c >= d);

to the overly verbose

	if (boolean == TRUE)
		something

	if (x && y || c >= d)
		boolean = TRUE;
	else
		boolean = FALSE;

Now *that* should start a really raging debate! :-)
-- 
Arnold Robbins
CSNET:	arnold at gatech	ARPA:	arnold%gatech.csnet at csnet-relay.arpa
UUCP:	{ akgua, allegra, hplabs, ihnp4, seismo, ut-sally }!gatech!arnold

Hello. You have reached the Coalition to Eliminate Answering Machines.
Unfortunately, no one can come to the phone right now....



More information about the Comp.lang.c mailing list