Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 60438 invoked from network); 26 Oct 2009 22:55:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 26 Oct 2009 22:55:56 -0000 Received: (qmail 94126 invoked by uid 500); 26 Oct 2009 22:55:56 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 94036 invoked by uid 500); 26 Oct 2009 22:55:56 -0000 Mailing-List: contact dev-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list dev@harmony.apache.org Received: (qmail 94025 invoked by uid 99); 26 Oct 2009 22:55:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Oct 2009 22:55:55 +0000 X-ASF-Spam-Status: No, hits=-3.6 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: 194.196.100.162 is neither permitted nor denied by domain of mark.hindess@googlemail.com) Received: from [194.196.100.162] (HELO mtagate2.uk.ibm.com) (194.196.100.162) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Oct 2009 22:55:51 +0000 Received: from d06nrmr1407.portsmouth.uk.ibm.com (d06nrmr1407.portsmouth.uk.ibm.com [9.149.38.185]) by mtagate2.uk.ibm.com (8.13.1/8.13.1) with ESMTP id n9QMtURf013386 for ; Mon, 26 Oct 2009 22:55:30 GMT Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by d06nrmr1407.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id n9QMtTJR1921278 for ; Mon, 26 Oct 2009 22:55:29 GMT Received: from d06av03.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n9QMtTXB029789 for ; Mon, 26 Oct 2009 22:55:29 GMT Received: from anaheim.local (sig-9-145-192-107.de.ibm.com [9.145.192.107]) by d06av03.portsmouth.uk.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id n9QMtTGE029775 for ; Mon, 26 Oct 2009 22:55:29 GMT Message-Id: <200910262255.n9QMtTGE029775@d06av03.portsmouth.uk.ibm.com> X-Mailer: exmh version 2.7.2 01/07/2005 (debian 1:2.7.2-18) with nmh-1.3 In-reply-to: References: Comments: In-reply-to Jesse Wilson message dated "Mon, 26 Oct 2009 14:57:24 -0700." From: Mark Hindess To: dev@harmony.apache.org Subject: Re: Idiomatic Java: inverted conditions Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Mon, 26 Oct 2009 22:55:29 +0000 In message , Jesse Wilson writes: > > Harmony Team, > > Continuing along with a theme, there's another C/C++ism in our Java > code that frustrates me. Our Java code frequently inverts conditions > from their natural language form. From HttpURLConnectionImpl: > > if (null == resHeader) { > > resHeader = new Header(); > > } Even in C this is largely unnecessary since we compile most code with: -Wall -Werror which should catch inadvertent assignments. > ...or even more surprising, from HttpURLConnection: > > if (0 < chunkLength) { > > throw new IllegalStateException(Msg.getString("KA003")); > > } This is definitely unnecessary. > I find myself having to slow down to interpret what the code > intends. I can't mentally parse "if 0 is less-than chunkLength" nearly > as efficiently as the equivalent "if chunkLength is greater than 0" > condition. From a quick survey of the code base, it looks like we use > a mix of the two forms. +1. I agree it significantly impedes the reading of code. > If anyone thinks I should avoid flipping of these conditionals back to > their normal form, please let me know. In my logging patch, I flipped > several "null == foo" checks and I found it made the code easier to > read. Again I'd rather separate patches but in this case it is trivial enough that it is probably okay to make them in other patches. -Mark.