harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Xiao-Feng Li <xiaofeng...@gmail.com>
Subject Re: Idiomatic Java: inverted conditions
Date Tue, 27 Oct 2009 13:35:21 GMT
On Tue, Oct 27, 2009 at 6:51 PM, Tim Ellison <t.p.ellison@gmail.com> wrote:
> On 26/Oct/2009 21:57, Jesse Wilson wrote:
>> 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.
> I'm sure we all have our own horror stories.  The ones that make me
> cringe are structured like this,
> public void foo(Object bar) {
>  if (bar != null) {
>    ...
>    <some long method, typically /too/ long>
>    ...
>    return result;
>  }
>  throw IllegalArgumentException();
> }
> Grrr.
> Tim

LOL. The code examples from Jesse, Alexey and Tim are all interesting.
When I saw those styles, I usually just assumed the authors must have
their strong justifications for that, since sometimes I saw the code
from some seasoned programmers and they refused to give an
explanation. :)  I might guess the original intention of the authors
is to help the (unwise) compiler to produce expected efficient code.
For example, with the code above, the author may expect the compiler
be silly and instruct it to produce fall-through code for the
most-frequently-taken branch. Well, with modern
microprocessor/compiler, this kind of code is (almost) no longer


View raw message