The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

2007 best coding practices

Last post 10-16-2007 3:40 PM by ammoQ. 19 replies.
Page 1 of 1 (20 items)
Sort Posts: Previous Next
  • 10-15-2007 3:52 PM

    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...

     
     

  • 10-15-2007 5:01 PM In reply to

    Re: 2007 best coding practices

    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.
     

  • 10-15-2007 5:03 PM In reply to

    • rbowes
    • Top 75 Contributor
    • Joined on 02-08-2007
    • Winnipeg, MB
    • Posts 412

    Re: 2007 best coding practices

    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!

  • 10-15-2007 5:13 PM In reply to

    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. 


    SpectateSwamp exposing aliens. Obviously the World needs SSDS


    [10:07] <fatdog> so from now on.. be sure to wear nice clean underwear
    [10:07] <mps> fatdog: That is simply not going to happen
  • 10-15-2007 5:16 PM In reply to

    • ammoQ
    • Top 10 Contributor
    • Joined on 04-13-2005
    • Vienna.Austria.Europe.Earth
    • Posts 3,445

    Re: WeatherGod's icon

    belgariontheking:

    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. 

    beanbag girl 4ever
  • 10-15-2007 5:44 PM In reply to

    Re: 2007 best coding practices

    Kilwch:

    //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.

    ╩юфют√ь ёЄЁрэшЎрь яюЁр эр яхэёш■.

    #TDWTF @ SlashNET was merged into #codelove @ the same network. You're still welcome to drop by. I guess.
  • 10-15-2007 5:59 PM In reply to

    • skippy
    • Top 200 Contributor
    • Joined on 03-10-2006
    • Calgary, AB
    • Posts 188

    Re: 2007 best coding practices

    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.
  • 10-15-2007 11:20 PM In reply to

    Re: WeatherGod's icon

    belgariontheking:

    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.
     

  • 10-15-2007 11:32 PM In reply to

    Re: 2007 best coding practices

    private boolean isNullOrZero(String aString) {
        return aString == null || aString.trim().matches("0*");
    }
    
    Should do quite nicely. I mean, is this stuff really that hard!?
  • 10-16-2007 3:24 AM In reply to

    • ammoQ
    • Top 10 Contributor
    • Joined on 04-13-2005
    • Vienna.Austria.Europe.Earth
    • Posts 3,445

    Re: WeatherGod's icon

    WeatherGod:
    belgariontheking:

    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.

    beanbag girl 4ever
  • 10-16-2007 4:53 AM In reply to

    Re: WeatherGod's icon

    WeatherGod:
    belgariontheking:

    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.

     

  • 10-16-2007 7:21 AM In reply to

    Re: WeatherGod's icon

    ammoQ:
    WeatherGod:
    belgariontheking:

    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.

  • 10-16-2007 8:57 AM In reply to

    • Erick
    • Not Ranked
    • Joined on 08-18-2006
    • South Carolina
    • Posts 46

    Re: 2007 best coding practices

    Well the problem with this code is quite obvious.
    He should have been using aString.IsVeryTrim()
  • 10-16-2007 9:05 AM In reply to

    Re: WeatherGod's icon

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

    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.  :-)
     

     
     

     

  • 10-16-2007 9:28 AM In reply to

    • ammoQ
    • Top 10 Contributor
    • Joined on 04-13-2005
    • Vienna.Austria.Europe.Earth
    • Posts 3,445

    Re: WeatherGod's icon

    shadowman:

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

    That's how I understood the post. 

    beanbag girl 4ever
  • 10-16-2007 9:37 AM In reply to

    Re: WeatherGod's icon

    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?
    TRWTF is Community Server
  • 10-16-2007 12:06 PM In reply to

    Re: WeatherGod's icon

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

    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?! 

  • 10-16-2007 12:22 PM In reply to

    Re: 2007 best coding practices

    Now wait a minute, I wanted 0.0...    

  • 10-16-2007 1:52 PM In reply to

    Re: WeatherGod's icon

    WeatherGod:

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

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

  • 10-16-2007 3:40 PM In reply to

    • ammoQ
    • Top 10 Contributor
    • Joined on 04-13-2005
    • Vienna.Austria.Europe.Earth
    • Posts 3,445

    Re: WeatherGod's icon

    asuffield:
    WeatherGod:

    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.

    beanbag girl 4ever
Page 1 of 1 (20 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems