Marick's Law 3

Posted by Uncle Bob Sat, 29 Nov 2008 20:12:00 GMT

A month ago I was deep in the throes of shipping the current release of FitNesse. I just wanted to get it done. I was close to delivery when I spotted a subtle flaw. To fix this flaw I decided to insert identical if statements into each of 9 implementations of an abstract function.

My green wrist band was glowing a nasty shade of puke. I knew I was duplicating code. I knew that I should use the Template Method pattern. But that just seemed too hard. I was convinced that it would be faster to spew the duplicated code out into the derivatives, get the release done, and then clean it up later.

So this morning I was doing something else, and I spotted this duplicated code. I sighed, as I looked down at my green wrist band, and thought to myself that I’d better eat my own dog food and clean this mess up before it gets any worse. I was dreading it.

I made sure that every occurrence of the statement was identical. Then I went to the base class with the intention of refactoring a Template Method. When, what to my wondering eyes should appear, but a Template Method that was already there.

I sheepishly copied and pasted the if statement from one of the derivatives into the Template Method, and then deleted the other eight instances.

I ran the tests.

They all passed.

Damn.

My green wrist band is shouting: “I TOLD YOU SO!”

For my penance I did 20 recitations of Marick’s law. “When it comes to code it never pays to rush.”

Comments

Leave a response

  1. Avatar
    llewellyn falco about 1 hour later:

    I agree with this, but I have to say that pairing makes it easier to implement. So much harder to slack off with others watching

  2. Avatar
    Mike Finney about 2 hours later:

    Hmmm. Perhaps we should make a plug-in for our IDE which has a little character applauding when it recognizes a refactoring we did. :) Perhaps a nice sound. (Ding!)

  3. Avatar
    Bret Pettichord 3 months later:

    And a raspberry when it sees us doing too much cut n paste.

Comments