The Handler



  • I was doing what seemed like a minor enhancement to a part of our system I have not seen before. All I had to do was create a handler to do one thing to some data, and call it from the appropriate place in the logic. The code looked like this:

        // other code
    myHandler.doNewThing(theData);

    // MyHandler:
    public void doNewThing(TheType theData) {
       // do work
    }
    

    My boss noticed what I had done, and suggested that I move the call to my handler into another handler that did some work at about the same point in the code. Ok, I'm easy, so now we have:

        // other code
        theOtherHandler.doOldThing(theData);
    
    // TheOtherHandler:
    public void doOldThing(TheType theData) {
       /* Code moved to new location X; left here for reference
           do old stuff
        */
       yetAnotherHandler.doYetAnotherThing(theData);
       myHandler.doNewThing(theData);
    }
    

    Hmmm, I'm detecting a pattern. I know I shouldn't, but I investigate. In location X, the code is a) completely different, and b) also commented out as: no longer needed.

    Uh oh.

    I cautiously go to YetAnotherHandler.doYetAnotherThing(...) and also find that the code is commented out, and noted that it has moved to location Y. I just know that I shouldn't, because it would upset me, but my curiosity got the better of me, and I went to location Y. Sure enough, the code is a) completely different, and b) also commented out as: no longer needed.

    And none of this stuff has been touched for 2 years (at least according to source control history).

    I rip out 2200 LOC, several handlers that do nothing, all of the code that was copied, changed and commented out at X and Y and all of the spring configurations to construct and inject this mess, and simply put a small 20 line function to do my new feature in the class where it's needed.

    Then, in our weekly training session (where the senior team members attempt to pass on knowledge), I spend an hour explaining to people why leaving stuff like this is, perhaps, not a best practice.



  •  where the hell do you live bro, your employers are consistently WTF factories.



  • I hope you don't get paid by the line, because you'd be poor by now.



  • Snoofle should clearly be paid by line removed.



  • @Kazan said:

     where the hell do you live bro, your employers are consistently WTF factories.

    It's been the same WTF factory for the past 4 years, although I joined this team 2 years ago.



  • @snoofle said:

    I rip out 2200 LOC, several handlers that do nothing, all of the code that was...
     

    And here I was hopping you'd just comment the lines that call those functions, and live them there as a joke...

    Do those people use a version control system?



  • @Mcoder said:

    Do those people use a version control system?
    @snoofle said:
    And none of this stuff has been touched for 2 years (at least according to source control history).



  • @Kazan said:

    where the hell do you live bro, your employers are consistently WTF factories.
    Hi, you must be new here. Welcome to The Daily Snoofle!



  • Just to be clear: they have source control, they don't necessarily use it.



  • @Mcoder said:

    Do those people use a version control system?
     

    Yes, VSS. Is there a problem?



  • @flabdablet said:

    Snoofle should clearly be paid by line removed.
     

    +1



  • @dhromed said:

    @Mcoder said:

    Do those people use a version control system?
     

    Yes, VSS. Is there a problem?

    Might as well use sharepoint for all your source control needs...

     



  • @galgorah said:

    @dhromed said:

    @Mcoder said:

    Do those people use a version control system?
     

    Yes, VSS. Is there a problem?

    Might as well use sharepoint for all your source control needs...

     

    Renaming files always works well as a VCS



  •  When I grow up, I want to be that epic go-to guy for gangsters and my name will be The Handler.



  • I currently work on a project with similar problems. The comments:LOC ratio is 1:5. At the same time, there are very few comments which are actually useful, because almost all of the comments are old, commented-out code. And yes, the project is under version control..



  • @dhromed said:

     When I grow up, I want to be that epic go-to guy for gangsters and my name will be The Handler.

    Aren't you afraid people will assume you're this person?


     



  • @dhromed said:

     When I grow up, I want to be that epic go-to guy for gangsters and my name will be The Handler.

    I certainly wouldn't like to be the target if someone decides to fire a trigger.

     



  • @Zecc said:

    fire a trigger.
     

    silly rabbit

    guns fire bullets, not triggers.

    triggers are entirely the wrong shape for gun barrels.



  • @da Doctah said:

    Aren't you afraid people will assume you're this person?
     

    No.



  • @snoofle said:

    My boss noticed what I had done, and suggested that I move the call to my handler into another handler that did some work at about the same point in the code.
    You're boss is definately right, there is a well established design pattern for such a thing. It's called the wrangler! You see the original handler should be termed the "wrangler" because it now manages how the other handlers do their thing.That way, if you ever have to change how the handler manges the handler, you just modify the wrangler. Don't you see how elegant this design is ;)



  • You're kidding about the wrangler pattern, but there are these patterns called chain-of-responsibilty and publish-subscribe, depending on what the handlers are meant to do.



  • And God-forbid you write a single line of code without flipping through the patterns book for three hours finding the best fit!!!

    Bow before the patterns book! Obey its holy pages!



  • @blakeyrat said:

    And God-forbid you write a single line of code without flipping through the patterns book for three hours finding the best fit!!!

    Bow before the patterns book! Obey its holy pages!

    Cool off.

    Patterns are good for general inspiration or for establishing a well-known name for an habitual form of implementation.

    They're obviously no substitute for common good sense in particular cases and shouldn't be used blindly.

     



  • Ah, memories.

    Last year or so, we ran Fortify (FindBugs writ large) against our codebase to find potential problems. Amongst other things, it found a couple places where someone hard-coded userids and passwords for database connections.

    A ticket was opened and a programmer assigned to the job of removing these hard-coded values.

    The ticket completed and I got the job of peer-reviewing it.

    Yep, you guessed it ... the lines were commented out, but still left there IN CASE WE EVER NEED THEM.


Log in to reply