IsNotReallyEmpty... or what?



  • Is was scanning through some code, trying to determine exactly what it
    did (some programmers have a problem with comments, believing that the
    only real documentation is source code) when I found a pretty obvious
    error:



       if (isEmpty(name)) {

            ptsReport.setName(name);

       }



    That is, I thought it was a bug until I found pretty similar code blocks:



        if (isEmpty(emplyeeSerial)) {

            ptsReport.setSerial(employeeSerial);

        }



    I decided to check out this infamous isEmpty method and lo and behold:



        protected boolean isEmpty(java.lang.String str)

        {

            return str != null && str.trim().length() != 0;

        }



    Clear and concise. Self-explanatory code!




  • it was Opposite Day when that was written.  that's all.



  • Actually, that's a great statement: "real documentation is source code". Thanks.

    But I agree in this case, the methode isEmpty should have had the following comment:

    <FONT color=#008000>// Return the oposite of what you think it does!</FONT>



  • @pink code said:


    I decided to check out this infamous isEmpty method and lo and behold:

        protected boolean isEmpty(java.lang.String str)
        {
            return str != null && str.trim().length() != 0;
        }

    <FONT face="Courier New" size=2>// ooo...sike!</FONT>



  • They were just looking after there own job.

    With code like this (as seen time and again on this site) if you write impossible code, no one else wants to support it - so they rehire you for support!! and then things continue to get worse...

     

    i think we could all learn a valuable lesson in Job Security from these people...


Log in to reply