Date: Wed, 06 Mar 2002 11:37:42 +0100 From: Poul-Henning Kamp <phk@critter.freebsd.dk> To: "Mike Meyer" <mwm-dated-1015842633.bc6005@mired.org> Cc: obrien@FreeBSD.ORG, Mike Meyer <mwm-dated-1015831171.a21ab0@mired.org>, Giorgos Keramidas <keramida@FreeBSD.ORG>, hackers@FreeBSD.ORG Subject: Re: RFC: style(9) isn't explicit about booleans for testing. Message-ID: <30203.1015411062@critter.freebsd.dk> In-Reply-To: Your message of "Wed, 06 Mar 2002 04:30:32 CST." <15493.61384.557931.883967@guru.mired.org>
next in thread | previous in thread | raw e-mail | index | archive | help
In message <15493.61384.557931.883967@guru.mired.org>, "Mike Meyer" writes:
>I'll grant that the change Paul suggested makes it clear - the
>programmer knows when the function is returning an int or not. But
>it's not clear that it achieves his intent. is
>
> char *p;
> if (p = somerandomfunction(with, args)) {
> }
>
>really less readable than:
>
> char *p;
> if ((p = somerandomfunction(with, args)) != NULL) {
> }
Ahh, but here you hit one of my pet-peeves. I hate assignments inside
conditionals. I prefer the above written as:
char *p;
p = somerandomfunction(with, args);
if (p != NULL) {
}
Anyway, if you want it spelled out the way I would want it:
0. No assignments in if()
1. In conditions, pointers should be explicitly compared against NULL:
if (foo == NULL)
or
if (foo != NULL)
2. In conditions, non-interger numeric types should be explicitly compared
to zero
if (float_t == 0.0)
3. Integers need not be explicitly compared to zero:
if (foo & MASK)
not
if ((foo & MASK) != 0)
--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?30203.1015411062>
