From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lx51b-0005o2-RH for qemu-devel@nongnu.org; Thu, 23 Apr 2009 15:55:59 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lx51X-0005nF-65 for qemu-devel@nongnu.org; Thu, 23 Apr 2009 15:55:59 -0400 Received: from [199.232.76.173] (port=49788 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lx51X-0005nC-3b for qemu-devel@nongnu.org; Thu, 23 Apr 2009 15:55:55 -0400 Received: from caffeine.csclub.uwaterloo.ca ([129.97.134.17]:39541) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Lx51W-0004ws-Hf for qemu-devel@nongnu.org; Thu, 23 Apr 2009 15:55:54 -0400 Date: Thu, 23 Apr 2009 15:55:53 -0400 Subject: Re: [Qemu-devel] [7234] Use a more natural order Message-ID: <20090423195553.GM3795@csclub.uwaterloo.ca> References: <20090423185308.GH3795@csclub.uwaterloo.ca> <20090423.131250.756905613.imp@bsdimp.com> <20090423192844.GJ3795@csclub.uwaterloo.ca> <20090423.134136.-135509976.imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090423.134136.-135509976.imp@bsdimp.com> From: lsorense@csclub.uwaterloo.ca (Lennart Sorensen) List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "M. Warner Losh" Cc: blauwirbel@gmail.com, qemu-devel@nongnu.org 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. > Correct. The compiler doesn't warn you that you've gotten your > backwards flipping around wrong. Which is the argument for this style > when it comes to equality. So you've traded one class of problems for > another. And this class of problem is just as hard to find. The compiler can't guess what your logic should be. It can tell that you tried to assign a value to a constant. > 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. > 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. This is why people writing safety critical code in C require this order. It is simply the safest choice. -- Len Sorensen