From: Jamie Lokier <jamie@shareable.org>
To: Lennart Sorensen <lsorense@csclub.uwaterloo.ca>
Cc: blauwirbel@gmail.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [7234] Use a more natural order
Date: Fri, 24 Apr 2009 00:02:57 +0100 [thread overview]
Message-ID: <20090423230257.GR13326@shareable.org> (raw)
In-Reply-To: <20090423195553.GM3795@csclub.uwaterloo.ca>
Lennart Sorensen wrote:
> On Thu, Apr 23, 2009 at 01:41:36PM -0600, M. Warner Losh wrote:
> > Hmmm, see how tricky this style is? It is confusing computing the
> > contrapositive to the expression you want to express. Or rather you
> > aren't computing the contrapositive here, which is what got me into
> > trouble. I usually don't make mistakes like this, and I made it in
> > coming up with the example.
>
> I wouldn't be surprised if there were languages other than english where
> the reverse would be the natural order, so I don't think your argument
> is worth much there.
I wouldn't be surprised either. But C is based on English, and most
programmers probably use a lot of English thinking.
Anyway, QEMU is definitely oriented around English as its main human
language :-)
> > I've fixed several bugs like this over the years from coders that
> > thought this was a good way to program.
> >
> > if (1 < x)
> >
> > rather than
> >
> > if (x < 1)
> >
> > is the most common pattern I've had to fix.
>
> Then you were fixing the wrong problem. The problem isn't the order,
> but simply that sometimes people get their logic backwards. The correct
> fix would have been:
>
> if (1 > x)
>
> if in fact the logic was backwards.
You missed the point entirely. *whoosh*
The point is that when
if (1 < x)
where "1 > x" was would have been correct, is a _more likely mistake
for most people to make_ than
if (x < 1)
because the latter is more familiar to most people. There is less
cognitive translation getting in the way of seeing what it means and
writing fluently.
The actual bug fix is irrelevant. The only thing relevant is which
style causes more mistakes.
> > I find this argument unpersuasive when the compiler will already warn
> > me about if (x = 0).
>
> Some compilers warn you. Not all do. An error from all compilers is
> also far better than a warning from some compilers.
You can make it an error with the only compiler that can build QEMU if
you want. I haven't seen any compiler which doesn't warn about it in
the last 10 years, except on machines which are more than 10 years old.
> This is why people writing safety critical code in C require this order.
> It is simply the safest choice.
I have a coding style which forbids this "safest choice" on the
grounds that it causes more mistakes than it avoids.
Of course I never use compilers which don't warn about it. That would
be really stupid - *especially* when writing safety critical code. If
you ignore _any_ warning in such code you are in big trouble.
Actually, these days for safety critical code it would be stupid not
to use the more advanced code checking tools such as Sparse...
-- Jamie
next prev parent reply other threads:[~2009-04-23 23:03 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-23 18:29 [Qemu-devel] [7234] Use a more natural order Blue Swirl
2009-04-23 18:39 ` Andreas Färber
2009-04-23 18:43 ` Blue Swirl
2009-04-23 18:53 ` Lennart Sorensen
2009-04-23 19:01 ` Blue Swirl
2009-04-23 19:10 ` Lennart Sorensen
2009-04-23 19:15 ` Glauber Costa
2009-04-23 19:39 ` Blue Swirl
2009-04-23 19:59 ` Anthony Liguori
2009-04-23 20:20 ` Blue Swirl
2009-04-23 19:57 ` Anthony Liguori
2009-04-23 19:59 ` Lennart Sorensen
2009-04-23 20:03 ` Anthony Liguori
2009-04-23 20:54 ` Lennart Sorensen
2009-04-23 21:15 ` Anthony Liguori
2009-04-23 22:13 ` Jamie Lokier
2009-04-24 0:10 ` Anthony Liguori
2009-04-24 8:18 ` Gerd Hoffmann
2009-04-24 12:14 ` Anthony Liguori
2009-04-24 12:32 ` Stefan Weil
2009-04-23 19:31 ` Blue Swirl
2009-04-23 19:44 ` Lennart Sorensen
2009-04-23 22:46 ` Jamie Lokier
2009-04-24 18:07 ` Lennart Sorensen
2009-04-24 18:58 ` Nathan Froyd
2009-04-23 19:12 ` M. Warner Losh
2009-04-23 19:28 ` Lennart Sorensen
2009-04-23 19:41 ` M. Warner Losh
2009-04-23 19:55 ` Lennart Sorensen
2009-04-23 20:07 ` M. Warner Losh
2009-04-23 21:01 ` Lennart Sorensen
2009-04-23 23:02 ` Jamie Lokier [this message]
2009-04-23 22:52 ` Jamie Lokier
2009-04-23 19:37 ` [Qemu-devel] " Jan Kiszka
2009-04-23 19:46 ` Lennart Sorensen
2009-04-23 21:30 ` malc
2009-04-23 22:10 ` Jamie Lokier
2009-04-24 8:09 ` [Qemu-devel] " Gerd Hoffmann
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=20090423230257.GR13326@shareable.org \
--to=jamie@shareable.org \
--cc=blauwirbel@gmail.com \
--cc=lsorense@csclub.uwaterloo.ca \
--cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).