From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lx7mn-0006BE-F0 for qemu-devel@nongnu.org; Thu, 23 Apr 2009 18:52:53 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lx7mi-0006Ae-Vy for qemu-devel@nongnu.org; Thu, 23 Apr 2009 18:52:53 -0400 Received: from [199.232.76.173] (port=55973 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lx7mi-0006Ab-Ob for qemu-devel@nongnu.org; Thu, 23 Apr 2009 18:52:48 -0400 Received: from mail2.shareable.org ([80.68.89.115]:49632) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Lx7mi-0004bb-8o for qemu-devel@nongnu.org; Thu, 23 Apr 2009 18:52:48 -0400 Date: Thu, 23 Apr 2009 23:52:42 +0100 From: Jamie Lokier Subject: Re: [Qemu-devel] [7234] Use a more natural order Message-ID: <20090423225242.GQ13326@shareable.org> References: <20090423185308.GH3795@csclub.uwaterloo.ca> <20090423.131250.756905613.imp@bsdimp.com> <20090423192844.GJ3795@csclub.uwaterloo.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090423192844.GJ3795@csclub.uwaterloo.ca> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Lennart Sorensen Cc: blauwirbel@gmail.com, qemu-devel@nongnu.org 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