Thursday, 15 July 2010

Refactoring as Time Machine

Dear Junior

If I had a time machine, I would not need to worry very much on how to invest my retirement pension plan. I could just pick any random fund, and if that one turns bad, I could just travel back in time and pick one that will succeed instead.

Now, who said that time travel should be free? If nothing else, the power to run it should send your electricity bill to unusual heights. So each time travel will certainly come with a fee. However, if it enables me to "have made" a better choice of pension plan thirty years ago, it would probably be worth it.


The Existential Angst of Making Decisions

How wonderful would that be, to not have to spend effort and energy on finding what hopefully is the best, and then have to worry about having made the wrong decision.

Unfortunately, I have no time machine. And chances are I will not have one either when time comes for me to retire, about thirty years from now.

So, boring and uninteresting it might be, I have to spend time and energy on investigating different choices to make a good one. And live with the angst.

In System Development We also make Decisions

When developing software, I constantly have to make a lot of decisions, small or big. It might be just what to name a method, or it might be how to split the system in tiers; still decisions, decisions, decisions. And, all those choices affect how easy the system will be to work with in the future - picking the wrong choice, and I will have a hard time.

Sometimes I find that I have earlier made a design- or architecture decision that "seemed like a good idea at the moment", but now feels like crap. Perhaps I should have spent a little more time and effort thinking over all possible futures?

In System Development We Have a Time Machine

To my delight, I have found that in system development I have the time machine I lack in financial investments. Often some not-too-complicated refactorings can "take me back in time" and change that template method solution (that does not suite me well any longer) to a shiny state and strategy pattern (that does suit my current needs).

Of course, the refactoring time travel is not for free - there is a fee to be paid in the work I have to do and the testing to ensure it went well. However, that fee is much lower than paying the price of continue working with a code-base that is not well aligned with my best-idea-at-the-moment.

Obviously, I still have to spend enough time and energy to find a decent solution when making a choice. The difference is that I do not have to spend the enormous effort to cover all options. The possibility of making future refactorings simply shrews the economics of making a decision. Refactorings make it possible to settle for a good solution now, keep the speed up, and pay the small fee for changing your mind in the future. And I can skip the "angst" part.

In that way refactoring is a wonderful little time machine.


Yours
  Dan


Ps The ability to do refactorings in the future makes it possible to keep options open longer, thus deferring decision-commitment. This is what I see as the central message of the Real Options-movement.

3 comments:

  1. First of all I believe word "angst" means anxiety(I asked to Google:) ).And of course I was just coming outside after a conversation on "Which suits? Big picture or Small?". If I read it before I could have definitely apply some "Time Machine" Thoughts :)

    Great and Nice thought, It sounds very well for me at the right time...

    ReplyDelete
  2. Dear Prasad

    Well, I might have over-exaggerated the "existential" dimension when using "Angst" to describe the anxious gut-feeling of "do I make the right decision now?".

    Nevertheless, having the "refactoring time-machine" and knowing that I can re-make the decision later, is what really cut down my level of anxiety in that decision.

    Glad the idea found a good fit for you at the time.

    Yours

    Dan

    ReplyDelete
  3. This is a really nice angle on refactoring - I like the idea that any mistakes in the past can be easily rectified :)

    I'm reading Refactoring at the moment, and although I'm finding the actual instructions a bit tedious, the general philosophy and discussion in the book is extremely stimulating, and has really made me think about programming in a different light.

    ReplyDelete