2007 best coding practices



  • The team I belong to is managing some activities like support, framework developpement. Support include pro-active support, like giving best practices and auditing some random applications to see if they are straightforward designed or WTF.

    • This one is supposed to be a convenience to know if a String is "null or zero" : the dev hopped it returned true if the argument was null, zero-length or containing only "00000....". Comments are mine.

    private boolean isNullOrZero(String aString) {
        boolean b = true;              //let's see later the use for this one...
        aString = aString.trim();      //Now aString is trimed so remember it is clean and safe to use !
        if (aString == null) {         //Dead code. If it was true, a NPEx would have been raised the line before ;p
            return true;
        }
        if (aString.trim().length() == 0) {//Re-trimming aString to be sure.
            return true;
        }
        int i = 0;
        while (i < aString.trim().length()) {//Triming each loop to be REALLY sure !
            if (aString.trim().charAt(i) != '0') { //Wait... can't remember if aString is trimed...
                return false;
            }
            i++;                            //Damn ! this "while" loop is strangely close to a "for"...
        }
        return b;                           //Now we can use the boolean initialized to true at the begining
    }

    • Some dev just can't get the point with MVC, especially controllers and Spring framework. Despite strong messages to discourage the use of instance attributes in controllers, they did so. So a few applications passed Quality Testing because it is done by 1 user a time, but crashed the first morning on production...

     
     



  • Wait, thare are jobs like that?  Do the clients ever listen to the suggestions?

     As for the code piece, I don't know what else to be said.  You seemed to capture all of my thoughts in your comments.  I am curious to see what their "corrected" version looks like.
     



  • I can take a guess how this evolved. It started with a line that was just "aString.trim()" which, of course, didn't work. So they added .trim() everywhere to fix it. Then somebody else came by and noticed the "aString.trim()" alone, and fixed it to "aString = aString.trim()". Voila!



  • Re: WeatherGod's icon

    This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux.  A simple answer will do, as opposed to a flamewar. 




  • @belgariontheking said:

    This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux.  A simple answer will do, as opposed to a flamewar. 


    Most likely anti-Linux. Read some of his other posts. 



  • @Kilwch said:

    //Now we can use the boolean initialized to true at the begining

    Mwa-ha-ha! Now this is where I really LMAO-ed. Y'know is could be used as a performance optimization technique. Just put:

    boolean true_value = true;
    boolean false_value = false;

    at the top of your files, so you won't have to recreate the values every time.



  • Take the overuse of "trim" in the while/for loop and change that to an equivalent redundant database lookup, and that's a lot of the code I had to fix to "improve performance".  Granted the DB lookup was hidden behind a C++ object, but the programmer(s) knew that.



  • @belgariontheking said:

    This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux.  A simple answer will do, as opposed to a flamewar. 

     It is supposed to be Pro-Linux.  I really can't think of any comments that I have made that would indicate that I am anti-Linux.  I am Pro-Linux, Pro-Mac all the way.  I just have no artistic skill whatsoever.
     



  • private boolean isNullOrZero(String aString) {
    return aString == null || aString.trim().matches("0*");
    }

    Should do quite nicely. I mean, is this stuff really that hard!?


  • @WeatherGod said:

    @belgariontheking said:

    This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux.  A simple answer will do, as opposed to a flamewar. 

     It is supposed to be Pro-Linux.  I really can't think of any comments that I have made that would indicate that I am anti-Linux.  I am Pro-Linux, Pro-Mac all the way.  I just have no artistic skill whatsoever.
     

    I think this one sounds rather anti-Linux, but maybe I've missed your point.



  • @WeatherGod said:

    @belgariontheking said:

    This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux.  A simple answer will do, as opposed to a flamewar.

     It is supposed to be Pro-Linux.  I really can't think of any comments that I have made that would indicate that I am anti-Linux.  I am Pro-Linux, Pro-Mac all the way.  I just have no artistic skill whatsoever.

    That reminds me of this comic strip. I hadn't seen that one for quite a while.

     


  • Winner of the 2016 Presidential Election

    @ammoQ said:

    @WeatherGod said:
    @belgariontheking said:

    This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux.  A simple answer will do, as opposed to a flamewar. 

     It is supposed to be Pro-Linux.  I really can't think of any comments that I have made that would indicate that I am anti-Linux.  I am Pro-Linux, Pro-Mac all the way.  I just have no artistic skill whatsoever.
     

    I think this one sounds rather anti-Linux, but maybe I've missed your point.

    That particular quote seems clearly pro-Linux.  Think of it in the light that all software has limitations, but closed-source software forces you to live with them where open-source software encourages you to fix them (and share your fix with the community).

    Windows Vista has been deliberately crippled in the name of Digital Rights Management.  Community driven software would never impose such things on you.



  • Well the problem with this code is quite obvious.
    He should have been using aString.IsVeryTrim()



  • @joe.edwards@imaginuity.com said:

    @ammoQ said:
    @WeatherGod said:
    @belgariontheking said:

    This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux.  A simple answer will do, as opposed to a flamewar. 

     It is supposed to be Pro-Linux.  I really can't think of any comments that I have made that would indicate that I am anti-Linux.  I am Pro-Linux, Pro-Mac all the way.  I just have no artistic skill whatsoever.
     

    I think this one sounds rather anti-Linux, but maybe I've missed your point.

    That particular quote seems clearly pro-Linux.  Think of it in the light that all software has limitations, but closed-source software forces you to live with them where open-source software encourages you to fix them (and share your fix with the community).

    Windows Vista has been deliberately crippled in the name of Digital Rights Management.  Community driven software would never impose such things on you.

    The relevant part of the quote was Isn't Linux's philosophy "Please work around any technical limitations in the software"?

    Perhaps he meant what you are talking about, but the confusion here is because "Work around" != "Fix".

    I'm sure Weather God is thrilled we're resorting to dissecting his forum posts like they're a high school literature assignment.  :-)
     

     
     

     



  • @shadowman said:

    Perhaps he meant what you are talking about, but the confusion here is because "Work around" != "Fix".

    That's how I understood the post. 



  • It is a bit ambiguous. Anti-LInux because it's saying one should pay to get a good OS? Or pro-Linux because it's saying Linux will cost you less than a quarter?



  • @shadowman said:

    @joe.edwards@imaginuity.com said:
    @ammoQ said:
    @WeatherGod said:
    @belgariontheking said:

    This has nothing to do with the post, but I'm trying to figure out whether WeatherGod's icon is pro- or anti-Linux.  A simple answer will do, as opposed to a flamewar. 

     It is supposed to be Pro-Linux.  I really can't think of any comments that I have made that would indicate that I am anti-Linux.  I am Pro-Linux, Pro-Mac all the way.  I just have no artistic skill whatsoever.
     

    I think this one sounds rather anti-Linux, but maybe I've missed your point.

    That particular quote seems clearly pro-Linux.  Think of it in the light that all software has limitations, but closed-source software forces you to live with them where open-source software encourages you to fix them (and share your fix with the community).

    Windows Vista has been deliberately crippled in the name of Digital Rights Management.  Community driven software would never impose such things on you.

    The relevant part of the quote was Isn't Linux's philosophy "Please work around any technical limitations in the software"?

    Perhaps he meant what you are talking about, but the confusion here is because "Work around" != "Fix".

    I'm sure Weather God is thrilled we're resorting to dissecting his forum posts like they're a high school literature assignment.  :-)
     

      

     

    Ok, I can see how that can be interpreated as anti-Linux.  I really didn't expect this level of attention here.  I will make it clear... I said "Work around" because that was the wording used in the OP of that thread.  Joe.Edwards's statement reflects what I meant by that statement.  In addition, my icon was inspired by the Dilbert comic mentioned above.

    Can we now focus back on the OP's WTF?! 



  • Now wait a minute, I wanted 0.0...    



  • @WeatherGod said:

    Can we now focus back on the OP's WTF?! 

    No. We have to obsess on this for a couple more pages first. 



  • @asuffield said:

    @WeatherGod said:

    Can we now focus back on the OP's WTF?! 

    No. We have to obsess on this for a couple more pages first. 

    Plus start two or three new threads about that topic, spread among the forums. But of course that doesn't put an end to the old thread.


Log in to reply
 

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