Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!mcvax!ukc!stc!praxis!tim
From: tim@praxis.co.uk (Tim Magee)
Newsgroups: comp.lang.c
Subject: Re: Writing readable code
Message-ID: <904@newton.praxis.co.uk>
Date: Fri, 10-Jul-87 14:56:22 EDT
Article-I.D.: newton.904
Posted: Fri Jul 10 14:56:22 1987
Date-Received: Mon, 13-Jul-87 00:53:25 EDT
References: <13008@topaz.rutgers.edu> <1941@zeus.TEK.COM>
Reply-To: tim@praxis.co.uk (Tim Magee)
Organization: Praxis Systems plc, Bath, UK
Lines: 61


	I'm catching up on comp.lang.c, due to a break in our news supply.
    this reply may duplicate something I haven't seen yet. From the tenor of
    previous articles, though, I doubt it.

In article <1941@zeus.TEK.COM> dant@tekla.UUCP (Dan Tilque) writes:
- Ron Natalie writes:
- >	I also wonder about people who define TRUE to be any
- >thing, since it leads to things like
- >	if( bool == TRUE )
- >which is different than
- >	if(!bool)
- I thought that TRUE and FALSE should be:
- #define FALSE 0
- #define TRUE !FALSE
- With these #defines the above two statements are equivalent.

	Are you absolutely sure? suppose 'bool' is TRUE, then the first
	says:
		if (TRUE == TRUE)
	while the second says
		if (!TRUE), or	if (!!FALSE).
	Are you still sure?

- >Generally, I use !p when I'm dealing with things that are supposed
- >boolean values like
- >	if(!isdigit(c))
- It's often easy to miss a single character (especially one that doesn't
- stand out like the "!") when quickly scanning code.
- 	if (isdigit(c) == TRUE)
- will compile to the same object code on almost every compiler...

	I quote from the SUN 3.2 UN*X manual page for is****, the ctype macros:

    'Each is a predicate returning non-zero for true, zero for false.'

	The two examples may well compile to the same object code. However the
    second example won't do anything like it seems to be aimed at achieving,
    because the ctype macros return the result of AND-ing integer constants of
    various values with members of an external array. A hallmark of readable
    code is that it does what it appears to say!

	The reason most people write obscure C is because they think it's
    faster. Why do they care? I guess most C programmers work on UN*X or a
    poor man's copy, and the amount of time UN*X spends executing other
    peoples' code is large enough to make your trivial 50 nanoseconds saving
    worth nothing.

	In the case of the 'isdigit' above, and making 'if (!isdigit(c))'
    less unreadable, how do you feel about:

#define NOT !
...
	if (NOT isdigit(c)) {

    Tim M.
-- 
    Tim Magee
...........P[{}([{>)}>>)}<(>]([)>}<[([{<[>)}}>)>]})]}[({>)>}...........
    "Eliminate the impossible, my dear Watson, and what remains..."
    "Is still an uncountably infinite set, Holmes."