The Power of a Bad Idea

Until recently one subsystem I own at Kubi was a mess. It worked for the most part, but it was fragile and hard to understand. The sad thing is I wrote most of it. It was one of the first things I took over when I joined Kubi and there was already a skeleton of an idea there. Unfortunately, I took that skeleton and put meat on it.



Once I had lived with the code long enough to learn the sad truth, I told my manager about the state of affairs and that I thought we needed to spend some time rewriting it. He was supportive of the idea and gave me a few days to do it. I figured, no problem, I've been doing this stuff for twenty years, I will just think about it for a while and type in a new solution. This is when my troubles began.



As I tried to think of a new approach to the problem, the existing implementation haunted my thoughts. I kept comming back to the same ideas that I knew had problems. Rather than do nothing and stare at the screen, I did what I normally do in this sort of situation, I refactored. I pulled the monster apart and examined the pieces.



Unfortunately, no new insights emerged, so I cleaned up the parts and put the thing back together. As I worked to address some of the issues that had necessitated this work, the same problems kept nagging me. The code needed something more but I couldn't tell what.



I reworked that code furiously for hours before the light finally dawned on me.
In retrospect the solution seems obvious - classic even. A judicious use of the MVC pattern and some better abstractions cleaned the whole mess up.



The reason I'm posting about this isn't because I think my solution is great or unique, rather the opposite. It's just a couple old lessons I keep learning and re-learning as time goes by. Programming is easy until it becomes hard and there's nothing harder to change than a plausible idea that just doesn't work.

Comments

Popular posts from this blog

Shark Crackers

Running roughshod or ripshod

Axis, Axes, Axii?