From: Peter Williams <peterw@aurema.com>
To: Willy Tarreau <willy@w.ods.org>
Cc: Linus Torvalds <torvalds@osdl.org>,
root@chaos.analogic.com, linux-kernel@vger.kernel.org, "Godbole,
Amarendra (GE Consumer & Industrial)" <Amarendra.Godbole@ge.com>,
"Randy.Dunlap" <rddunlap@osdl.org>
Subject: Re: (0 == foo), rather than (foo == 0)
Date: Thu, 11 Mar 2004 18:36:02 +1100 [thread overview]
Message-ID: <405016E2.4030208@aurema.com> (raw)
In-Reply-To: <20040311065041.GB14537@alpha.home.local>
Willy Tarreau wrote:
> Hi,
>
> On Wed, Mar 10, 2004 at 06:36:22PM -0800, Linus Torvalds wrote:
>
>>And while "0 == foo" may be logically the same thing as "foo == 0", the
>>fact is, the latter is what people are used to seeing. And by being used
>>to seeing it, they have an easier time thinking about it.
>>
>>As a result, using the former just tends to increase peoples confusion by
>>making code harder to read, which in turn tends to increase the chance of
>>bugs.
>
>
> I have a friend who constantly uses it, and his code is unreadable, because
> sometimes, a "0 == xxx" becomes "0 <= xxx" or "0 >= xxx" which is difficult
> to understand. Thinking that xxx is negative because it's written on the
> right side of a >= is complicated. And the worst he does is when he uses
> functions :
>
> if (0 < strcmp(a, "xxx")) ...
> if (sizeof(t) > read(fd, t, sizeof(t)) ...
>
> I have already helped him track bugs in his programs, and some of them were
> just related to this usage, because nobody's brain can understand these
> constructions immediately without thinking a bit. So I'm all against this
> sort of thing.
One final note. I agree with all the statements of how awkward and
unnatural the back to front boolean expressions look but I had adopted
this technique (for myself) as a means of overcoming design shortcomings
in the C language. I intend to keep doing it in my private code (as
it's saved my bacon a number of times) but will conform to Linus's
standards for any contributions/patches I submit for kernel code (just
as I would conform for any other person's standards if I were to
contribute to their work). In the long run, consistency in a body of
code greatly enhances its readability.
Peace?
Peter
--
Dr Peter Williams, Chief Scientist peterw@aurema.com
Aurema Pty Limited Tel:+61 2 9698 2322
PO Box 305, Strawberry Hills NSW 2012, Australia Fax:+61 2 9699 9174
79 Myrtle Street, Chippendale NSW 2008, Australia http://www.aurema.com
next prev parent reply other threads:[~2004-03-11 7:36 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-10 6:16 (0 == foo), rather than (foo == 0) Godbole, Amarendra (GE Consumer & Industrial)
2004-03-10 10:34 ` Bernd Petrovitsch
2004-03-10 18:02 ` Randy.Dunlap
2004-03-10 18:33 ` Richard B. Johnson
2004-03-10 18:50 ` [OT] " David Ford
2004-03-10 19:06 ` Roland Dreier
2004-03-10 19:26 ` David Ford
2004-03-10 21:26 ` Roland Dreier
2004-03-10 22:03 ` Måns Rullgård
2004-03-11 23:12 ` Bill Davidsen
2004-03-10 19:23 ` Richard B. Johnson
2004-03-10 19:31 ` David Ford
2004-03-10 23:20 ` Frank v Waveren
2004-03-10 23:33 ` Måns Rullgård
2004-03-11 2:14 ` David Ford
2004-03-11 15:06 ` Valdis.Kletnieks
2004-03-10 23:10 ` Peter Williams
2004-03-10 21:29 ` viro
2004-03-10 22:20 ` David Ford
2004-03-10 22:42 ` Richard B. Johnson
2004-03-11 0:33 ` Micha Feigin
2004-03-11 10:47 ` Giuseppe Bilotta
2004-03-10 22:49 ` Stefan Smietanowski
2004-03-10 23:14 ` David Ford
2004-03-10 23:28 ` Måns Rullgård
2004-03-10 23:47 ` Stefan Smietanowski
2004-03-10 21:34 ` Matthew Garrett
2004-03-10 23:00 ` Peter Williams
2004-03-11 0:16 ` Randy.Dunlap
2004-03-11 2:36 ` Linus Torvalds
2004-03-11 3:08 ` Peter Williams
2004-03-11 3:19 ` Linus Torvalds
2004-03-11 4:40 ` Stefan Smietanowski
2004-03-11 9:48 ` Måns Rullgård
2004-03-11 10:29 ` Stefan Smietanowski
2004-03-11 15:18 ` Andreas Schwab
2004-03-11 17:42 ` Stefan Smietanowski
2004-03-11 23:05 ` Bill Davidsen
2004-03-11 6:50 ` Willy Tarreau
2004-03-11 7:36 ` Peter Williams [this message]
2004-03-11 15:03 ` Valdis.Kletnieks
2004-03-11 15:22 ` Richard B. Johnson
2004-03-11 15:48 ` Valdis.Kletnieks
-- strict thread matches above, loose matches on Subject: below --
2004-03-11 4:04 Godbole, Amarendra (GE Consumer & Industrial)
[not found] <1y5oc-8cr-1@gated-at.bofh.it>
[not found] ` <1ygjH-3LE-31@gated-at.bofh.it>
[not found] ` <1ygMH-4eu-21@gated-at.bofh.it>
[not found] ` <1yzZ9-1qq-43@gated-at.bofh.it>
[not found] ` <1yAs0-1P6-7@gated-at.bofh.it>
[not found] ` <1yALu-288-5@gated-at.bofh.it>
2004-03-11 16:41 ` Chip Salzenberg
[not found] <1ypPV-5N2-3@gated-at.bofh.it>
2004-03-11 16:44 ` Chip Salzenberg
2004-03-11 23:57 ` Peter Williams
2004-03-12 1:51 ` Chris Johns
2004-03-12 12:21 ` Richard B. Johnson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=405016E2.4030208@aurema.com \
--to=peterw@aurema.com \
--cc=Amarendra.Godbole@ge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rddunlap@osdl.org \
--cc=root@chaos.analogic.com \
--cc=torvalds@osdl.org \
--cc=willy@w.ods.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.