IsNull or IsNotNull?



  • I think we had this (or something similar) before. But anyway. I was getting furious when I just saw that snippet in one of my colleagues code:

     

    public static final boolean IsNull(Object inObject) {
    <nbsp><nbsp><nbsp><nbsp>return (null == inObject);</nbsp></nbsp></nbsp></nbsp>
    <nbsp><nbsp><nbsp><nbsp></nbsp></nbsp></nbsp></nbsp>
    <nbsp><nbsp><nbsp><nbsp> }

    public static final boolean IsNotNull(Object inObject) {
    </nbsp></nbsp></nbsp></nbsp>
    <nbsp><nbsp><nbsp><nbsp><nbsp><nbsp> return (!IsNull(inObject));</nbsp></nbsp></nbsp></nbsp></nbsp></nbsp>
    <nbsp><nbsp><nbsp><nbsp><nbsp><nbsp></nbsp></nbsp></nbsp></nbsp></nbsp></nbsp>

    <nbsp><nbsp><nbsp><nbsp><nbsp><nbsp> }</nbsp></nbsp></nbsp></nbsp></nbsp></nbsp>

    Of course, that piece of sh..t is called heavily from the rest of his code. I'm on to a little refactoring. As I already explained to another colleague of mine: the best refactoring consists of:

    1. select the code to refactor
    2. press the "Delete" button 

     Or am I missing some great advantage to the above code?
     

    (BTW: sorry for the strange formatting of the code. I can't seem to master the editing tool of this forum) 



  • Perhaps they wanted to bottleneck all the tests against null  in order to:

     

    (1)  Sometime in the future count all the comparisons against null.

     

    (2)  If necessary add some patch in there where the object might be not null, but equivalent, such as the empty string, or  "NULL" , or some other data that might have sneaked into the data

     

    (3)  As a quick thing to eventually change and get a slight performance boost. :)

     

     



  • Perhaps it's incase the value of NULL changes in the future? A quick change to the function and disaster is avoided!



  • Ooooh yummy! With that you can write...

     

    if ( !IsNotNull( obj ) ) {

     ...

    }

     

    :D 



  • they're getting there. appears they have moved on and progressed from the doNothing() and isTrue() methods.     



  • Your colleague forgot the following function :

    public static final boolean IsFileNotFound(Object inObject) {
    return (!IsNull(inObject) && !IsNotNull(inObject));
    }



  • @Vechni said:

    they're getting there. appears they have moved on and progressed from the doNothing() and isTrue() methods.     

     

    Ooh what a good idea.... ;)

    if( IsTrue( !IsNotNull(obj) )) {

     
     



  • @Claxon said:

    @Vechni said:

    they're getting there. appears they have moved on and progressed from the doNothing() and isTrue() methods.     

     

    Ooh what a good idea.... ;)

    if( IsTrue( !IsNotNull(obj) )) {

     
     

     

    ...

    Oh screw you guys.  I'm gonna go become a hermit somewhere there's no electricity, because clearly technology is retarded. 



  • @TheRider said:

    I think we had this (or something similar) before. But anyway. I was getting furious when I just saw that snippet in one of my colleagues code:

     

    public static final boolean IsNull(Object inObject) {
    <NBSP><NBSP><NBSP><NBSP>return (null == inObject);</NBSP></NBSP></NBSP></NBSP>
    <NBSP><NBSP><NBSP><NBSP></NBSP></NBSP></NBSP></NBSP>
    <NBSP><NBSP><NBSP><NBSP>}

    public static final boolean IsNotNull(Object inObject) {
    </NBSP></NBSP></NBSP></NBSP>
    <NBSP><NBSP><NBSP><NBSP><NBSP><NBSP>return (!IsNull(inObject));</NBSP></NBSP></NBSP></NBSP></NBSP></NBSP>
    <NBSP><NBSP><NBSP><NBSP><NBSP><NBSP></NBSP></NBSP></NBSP></NBSP></NBSP></NBSP>

    <NBSP><NBSP><NBSP><NBSP><NBSP><NBSP>}</NBSP></NBSP></NBSP></NBSP></NBSP></NBSP>

    Of course, that piece of sh..t is called heavily from the rest of his code. I'm on to a little refactoring. As I already explained to another colleague of mine: the best refactoring consists of:

    1. select the code to refactor
    2. press the "Delete" button 

     Or am I missing some great advantage to the above code?
     

    (BTW: sorry for the strange formatting of the code. I can't seem to master the editing tool of this forum) 

    What about

    public static final boolean MightBeNull(Object inObject) {
              boolean retVal = false;
              return true;
    }



  • @TheRider said:

    I think we had this (or something similar) before

    It is a very common example of brillant behaviour. We see it a lot because people do it a lot. 



  • @misguided said:

    Oh screw you guys.  I'm gonna go become a hermit somewhere there's no electricity, because clearly technology is retarded. 

    It's people that are retarded, so you need to go somewhere there's no people.

    Conveniently, this is what the word "hermit" means.
     


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.