I've got a fever...



  • ...and the only cure is more ternary operations!

    public boolean isNameSearch()

    {

       return inputSearchType.equals("name") ? true : false;

    }

    It's double-plus true!  And it's all over my codebase!

     
    Seriously, if you, as a programmer, do not understand basic boolean logic, the kind taught in those first year discrete math courses in any decent CS program, please do the rest of us a favor and consider a career change.  Thank you!
     



  • Is that worse than "if (x == true) return true; else return false;" ?



  • It could be worse.

    Why is Boolean the source of so many WTFs? It seems like it's 1-2 a day, in this forum only...



  • @H|B said:

    Why is Boolean the source of so many WTFs? It seems like it's 1-2 a day, in this forum only...

    Seriously, it's like the simpler something is, the more spectacular ways people find to screw it up.  



  • I think it's because novice programmers (maybe some senior programmers, too) are so used to seeing:

    if (condition)
        //

    else
       //
     

    so they just try to fit everything into that construct.  There might also be a disconnect between using boolean as a return type and seeing it in an if-statement.

    I just cleaned a few of these guys up myself.  Turns out IntelliJ IDEA has a built-in wizard that finds these guys and will correct them automatically if you click on the little icon that shows up in the margin. 



  • @livid said:

    ...and the only cure is more ternary operations!

    public boolean isNameSearch()

    {

       return inputSearchType.equals("name") ? true : false;

    }

    It's double-plus true!  And it's all over my codebase!

     
    Seriously, if you, as a programmer, do not understand basic boolean logic, the kind taught in those first year discrete math courses in any decent CS program, please do the rest of us a favor and consider a career change.  Thank you!
     

     

    Here is that code refactored, with the new quartenary operator in C

    public boolean isNameSearch()

    {

       return inputSearchType.equals("name") !? true : false : file_not_found ;

    }

     


  • Discourse touched me in a no-no place

    @m0ffx said:


    Here is that code refactored, with the new quartenary operator in C

    public boolean isNameSearch()

    {

       return inputSearchType.equals("name") true : false : file_not_found ;

    }

     

    There, fixed that for you. HTH.



  • @PJH said:

    There, fixed that for you. HTH.
     

    Needs more cow bell. 


Log in to reply
 

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