cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Berin Loritsch <blorit...@apache.org>
Subject Re: Coding style question: backwards null checks
Date Fri, 07 Mar 2003 14:20:32 GMT
Jeff Turner wrote:
> Hi,
> 
> Quick question.  Why do people put null checks backwards:
> 
>   if ( null != this.inputSource ) {
> 
> IMHO it is harder to read than
> 
>   if ( this.inputSource != null ) {
> 
> and means exactly the same thing.

Yep.

> I think this is a throwback from the days of C, where swapping the
> conditions was a handy way to avoid =/== bugs like:
> 
>   if ( this.inputSource = null ) {
> 
> But in Java, the compiler catches this error:
> 
> Found 1 semantic error compiling "Test.java":
> 
>     10.                 if (inputSource = null) {
>                             <---------------->
> *** Error: The type of this expression, "Source", is not boolean.

I see.

> So is there any other reason for this?  Can I do a massive grep for 
> 'null !=' and change these?

No, I think that is the major reason.


Mime
View raw message