aries-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alasdair Nottingham <...@apache.org>
Subject Re: Why !!! in "if(!!!clazz.isInterface())" ?
Date Wed, 24 Nov 2010 18:40:38 GMT
Makes you wonder about the compiler author, I wonder if they have tests for all these variants.

Alasdair

On 24 Nov 2010, at 14:54, Stuart McCulloch <mcculls@gmail.com> wrote:

> On 24 November 2010 14:47, Alasdair Nottingham <not@apache.org> wrote:
> 
>> I find !!! is obviously odd where !!!!! and !!!!!!! are not. I could
>> go for == false, but I've always thought that makes it look as if you
>> don't realize Java has a boolean data type. I also expect it is more
>> byte code.
> 
> 
> sigh, save us from premature optimization ;)
> 
> you'll be happy to know that both !, !!!, and == false compile down to the
> same single bytecode operation
> 
> On 24 November 2010 14:31, David Bosschaert <david.bosschaert@gmail.com>
>> wrote:
>>> Ok - so at least no magic stuff happening that I wasn't aware of :)
>>> 
>>> One could argue that !!!!! is even more visible or !!!!!!! or !!!!!!!!
>>> - hold on? did I forget one '!' ? ;)
>>> If you're going for explicit, Stuart's suggestion of == false is
>>> probably a little safer...
>>> 
>>> Cheers,
>>> 
>>> David
>>> 
>>> On 24 November 2010 14:10, Timothy Ward <timothyjward@apache.org> wrote:
>>>> 
>>>> You'll find quite a few of these littered around the Aries codebase.
>> It's a bad habit I picked up from Alasdair ;)
>>>> 
>>>> I actually like it, it's nearly as concise as !, but much easier to spot
>> and obviously different from !!!! or !!
>>>> 
>>>> Regards,
>>>> 
>>>> Tim
>>>> 
>>>> ----------------------------------------
>>>>> From: not@apache.org
>>>>> Subject: Re: Why !!! in "if(!!!clazz.isInterface())" ?
>>>>> Date: Wed, 24 Nov 2010 14:01:37 +0000
>>>>> To: aries-dev@incubator.apache.org
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> It is equivalent to if(!clazz.isInterface()), but in my view is more
>> visible. The compiler even optimises it to a single negation.
>>>>> 
>>>>> I find it really helps as I often mis a single ! when reading code.
>>>>> 
>>>>> Alasdair
>>>>> 
>>>>> On 24 Nov 2010, at 13:18, David Bosschaert  wrote:
>>>>> 
>>>>>> Hi all,
>>>>>> 
>>>>>> While looking around in some of the Aries codebase I found the
>>>>>> following line of code [1]:
>>>>>> 
>>>>>> if(!!!clazz.isInterface()) { //...
>>>>>> 
>>>>>> Isn't this equivalent to if(!clazz.isInterface()) ? Or is there some
>>>>>> special magic happening here that I haven't seen before?
>>>>>> 
>>>>>> Just curious...
>>>>>> 
>>>>>> Cheers,
>>>>>> 
>>>>>> David
>>>>>> 
>>>>>> [1]
>> http://svn.apache.org/repos/asf/incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/AsmProxyManager.java
>>>> 
>>> 
>> 
>> 
>> 
>> --
>> Alasdair Nottingham
>> not@apache.org
>> 
> 
> 
> 
> -- 
> Cheers, Stuart

Mime
View raw message