qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [7234] Use a more natural order


From: Jamie Lokier
Subject: Re: [Qemu-devel] [7234] Use a more natural order
Date: Thu, 23 Apr 2009 23:52:42 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

Lennart Sorensen wrote:
> > if (x < 1)
> > 
> > becomes
> > 
> > if (1 >= x)
> 
> No it doesn't.  It becomes:
> 
> if (1 > x)

Exactly.

You just proved that it's error prone to someone unfamiliar with it.

We all see the mistake now.  But it was too easy to make in the first
place.  Maybe you never do that, but you have to choose practices
which don't trigger mistakes from others too.

> > The compiler will warn about your example, but won't warn if I
> > transcribe things wrongly as
> > 
> > if (1 < x)
> 
> Nothing wrong with that.  That's perfectly valid, if you want to check
> that x is greater than 1.

By transcribing he meant that one is prone to writing "if (1 < x)" _by
accident_ when one means to check that x is less than 1.  Even worse,
the mistake is prone to being missed when reading it too.

> Putting constants first means that you can't accidentally use assignment
> when you meant equality.  You can't fix all the stupidies possible in C,
> but you can at least try to avoid some of them when possible.

You can't do that anyway, without a warning or error, with any
compiler released in the last 10 years.  Unless you're so stupid as to
turn that warning off.  Now that _would_ be a stupidity possible in C :-)

-- Jame




reply via email to

[Prev in Thread] Current Thread [Next in Thread]