harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Ellison <t.p.elli...@gmail.com>
Subject Re: Idiomatic Java: inverted conditions
Date Tue, 27 Oct 2009 14:21:14 GMT
On 27/Oct/2009 13:35, Xiao-Feng Li wrote:
> 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
> needed.

I agree Xiao-Feng, and that is a poor reason to write code in this style
anyway.  I would even suggest that coding for the compiler and coding
for the next person who has to read the code are usually complimentary,
such as marking fields as final, and using the most restrictive possible
method scope, etc.  Of course, these details are usually swamped by
higher-level algorithm choice anyway.


View raw message