Re: (0 == foo), rather than (foo == 0)

From: Peter Williams (peterw_at_aurema.com)
Date: 03/11/04

  • Next message: David Mosberger: "RE: [PATCH] fix PCI interrupt setting for ia64"
    Date:	Thu, 11 Mar 2004 18:36:02 +1100
    To: Willy Tarreau <willy@w.ods.org>
    
    

    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
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at  http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at  http://www.tux.org/lkml/
    

  • Next message: David Mosberger: "RE: [PATCH] fix PCI interrupt setting for ia64"

    Relevant Pages

    • Re: Interrupt lost { .... }
      ... > CHS current addressable sectors: ... > not expired: security count ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: Malcolms new book - Chapter 1 review
      ... not written in C that happens to conform to the standards of the day ... CLAMP draws the attention that no, ... a function, it is a macro, so beware. ...
      (comp.lang.c)
    • Re: JTF: Javascript Unit Testing Farm
      ... he built his company on standards compliance. ... to conform to IBM's PC hardware standard, cpu, bus protocol etc. ... I am not sure if it is MS proper or Bill Gates that owns the stock but Apple stock is owned by either MS or Bill Gates directly. ... Bill Gates couldn't give a crap whether they produce a good product or not - as long as the product they have is dominant. ...
      (comp.lang.javascript)
    • Re: Kadaitcha_Mommys time stamp.
      ... Phineas T Puddleduck wrote: ... I pick the standards that suit me best and discard the rest. ... You refuse to conform to Windows GUI standards. ...
      (sci.physics)
    • Re: big brother coopting google (et al)
      ... "copy-protection" schemes built right into the standards these HDTVs ... have to conform to ...
      (rec.arts.sf.written)