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

Frank Adams franka at mmintl.UUCP
Tue Aug 27 13:01:24 AEST 1985


In article <989 at gatech.CSNET> arnold at gatech.CSNET (Arnold Robbins) writes:
>
>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 */
>
>
>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.).

The problem with your solution is I can just easily write

	dowrite(file, APPEND, NOFORCE, ...)

and will have a terrible time finding the error.  This is where Ada wins:

	dowrite(file, append=>true, force=>false, ...)

is clear, simple, and error-resistant.



More information about the Comp.lang.c mailing list