a bit of refactoring

In software engineering, “refactoring” a source code module often means modifying without changing its external behavior, and is sometimes informally referred to as “cleaning it up”.

In particular, adding new behavior to a program might be difficult with the program’s given structure, so a developer might refactor it first to make it easier, and then add the new behavior. Refactoring is also a tool for removing bad code smells that exist in code.

~ Refactoring

what is refactoring?

Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a ‘refactoring’) does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it’s less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.

~ Martin Fowler’s site on Refactoring

Sometimes code gets messy over time, and investing some time not developing something new, but simply refactoring what already is there, really reduces a lot of time in maintenance results in a significant boost to productivity.

But the most common obstacle for refactoring is “I’m too busy to do it!

And so, given a programming task on some old complicated source code, there are two options. One is to straightaway start with the task – wrangling with timelines, struggling to debug and decrypt the code in order to complete a given task. An other is to spend time in refactoring and sorting things out first (with test cases) and then actually start with the given task. Of course there’s no ‘best’ solution but it depends on the situation.

The first one seems to be the easiest. The second option may require some courage – because there seems to be the somewhat overwhelming risk that it might affect the entire system, introduce new bugs, end up as a dead investment if the refactoring cannot be completed succesfully… all kinds of difficulties!

Socrates had said…

An unexamined life is not worth living.

Not sure exactly what he might’ve meant, but one guess is that he could be talking about refactoring one’s life.

I’ve actually done that gradually over the past year or so, and have found that it has tremendously improved the quality of my life.

For example, a lot of time was being occupied in driving around in traffic. I took up a new job (not the only reason of course) and moved to a new house to live in. Now my new workplace is just 15 minutes drive from home. This is not a single drastic event but happened gradually over time.

One more thing is I gave up ambitions of climbing the corporate ladder gaining a better and better position, to lead other people and so on (and earn higher and higher salary of course!). Instead, I decided my priority was simply to become a “good developer”. Btw this is below the dignity of a lot of software engineers, because compared to a construction industry, programming is like the basic cementing job which freshers from college do. At first this seemed to be a total lack of ambition. But this makes me happy, and I have any interest in impressing anyone with a sophisticated designation 😉 And my new job respects this attitude.

Another idea is that 4 to 7 PM is the most beautiful time in the evening, best spent roaming around in a park or on the terrace watching the sunset with my son, instead of sitting in front of a computer. Since I have an option to work from home (depending on the project team situation), I often leave for home around 4 PM and really have a nice outdoor evening either on the terrace. continue working from home when it gets dark. This balances working with the rest of the team in the office, and has an added advantage that it also gives me some extra overlap time with my American colleagues.

The above ideas worked well for me. There are some other things I tried which didn’t work out. But I’m glad I did give them a try, and experimented with life.

Maybe you may not have the same opportunity (to work from home, for example) but you may have other even better possibilities, if only you would examine with a fresh perspective. I would love to hear your experience if you’ve want to try/have tried out anything new.

One thing that this speaker he himself is a world traveller travelling all over the place meeting so many people all over the world… had said “I pity you, you meet the same people – same family members – same colleagues – day after day” But I disagree (and also possibly disagreement was a reaction the speaker hoped to provoke). As long as one manages to avoid getting caught in a mechanical daily routine, one can see the newness in every day and in every person around them! 😎

It made a lot more sense to begin with whatever I have, instead of wishing for something else. I started becoming more sincere about whatever I was doing, including my job. So rather than begin by changing external circumstances, I looked at how I could change the way I was handling them. The external changes happened as a natural consequence, without too much effort.

3 Responses to “a bit of refactoring”

  1. Anitha Says:

    Nice post.I agree with you , it is essential to examine our life every now and then.

    Here is what I tried out … Sleep early, get up early , leave early to office , as soon as my children leave fo school , which is around 7.45 and then come back home by 6.00 … I feel I am getting quite a bit of time with my Children.
    Like you … I too shifted (2 years back) to an office which is closer to my home.

    Sanjay … I am hoping that you will start “Muktha Muktha” blog again , since the serial has started yesterday 🙂

  2. msanjay Says:

    thanks Anitha that sounds pretty nice.

    Muktha page is already active probably I will take up your idea and create a new page… veena has also created a very nice muktha muktha page as well

  3. Add To C3 Kids. | 7Wins.eu Says:

    […] […]

Leave a Reply