Thursday, July 15, 2010

Refactoraholics Anonymous

Hello, my name is Aleks and I'm a refactoraholic.

First time I noticed the interest in refactoring when I was around 18-19, just starting to write my first decent-sized pascal and C++ programs. First I wrote my programs the ugly way, and then I wanted to write them better. While this drive in and of itself was natural, I found myself more interested in making the code pretty than the end result of what it does. I noticed getting this addictive feeling when I refactoring, and ended up rewriting old projects until they were "perfect", even though there would be no functional benefit from it. Such purification activity on code seemed to have no purpose, as the code either:
a) already did what it was supposed to do or
b) was part of a curriculum course that I already finished, and thus working extra wouldn't improve my grade, or
c) it was part of a research project in grad school which needed more results, and instead of getting more results I found myself spending more time on refactoring.

It was very much a compulsion, whose power I didn't realize. Each time I did refactoring, it felt like it just HAD to be done, and each time it had very detremental effect on the project at hand. Naturally the existing functionality broke, my project's deadline slipped. I spent sleepless nights, and long weekends trying to get myself out of the mess. The code was prettier, more modular, more decoupled, more readable, but functionally it deteriorated, and it took me a while to get it to its original stability and use cases. Before I discovered source control, starting refactoring meant that I had to finish it, which cost me a lot of sweat and tears. Even when I did discover source control, I was very reluctant to back out the changes because I always gravitated towards a more modular version of the code, regardless of the cost.

 I cursed myself for starting the process, knowing full well I would have been better off not going there. But it was too late. I was in the middle of refactoring, everything was broken, I would be lucky if the code compiled let alone work as intended. Oh yeah, in the meantime I needed to get new functionality in, and by the time I cleaned up the mess, I would forget where I was and why I started the whole cleanup in the first place.

I considered going to a refactoring-shrink, who may have been able to advise me properly out of the situation, but who knows I could have gotten one of those old-school hacker dudes, who would have told me to be a man and just write the whole project in C already. I was too timid to come out of the refactoring closet, and too stubborn to stop, I was stuck in an evil loop. At the same time while I was aware of the problem, I was a little bit in denial, since refactoring felt so good. It was like a drug to me, I couldn't get enough. And despite all the pain it's put me thru, I kept at it. Each new project was refactored, again and again, and it's almost like I didn't learn from my mistakes.

I felt completely alone. My parents didn't know about my addiction, I didn't think they would understand. Most of my non-programming friends naturally couldn't relate at all. How do you explain refactoring of code to someone who doesn't even understand what code is all about?
But even most of my fellow programmers didn't share my passion, they thought I was a weirdo, spending endless hours on a useless activity.

I had a passion for writing code well, but it didn't seem to pay off. Was I doomed to an eternity of toil and frustration?... (to be continued)

No comments:

Post a Comment