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

Stew Rubenstein stew at harvard.ARPA
Sat Aug 31 12:12:58 AEST 1985


In article <625 at mmintl.UUCP> franka at mmintl.UUCP (Frank Adams) writes:
>
>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);
>...
>  >	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, ...)

In a perfect world, the argument types for dowrite() would be declared
as different enum types and the compiler will complain if you mix them
up (i.e. in new ANSI C if I understand it right).  In a slightly less
perfect world, lint would complain about the inconsistency.  We were
talking conceptually, right?  Not to say that the keyword style isn't
better, but this is one the compiler ought to catch.

Stew



More information about the Comp.lang.c mailing list