Re: Beautiful Code in the Real World - Part II: Scorn Globally, Act Locally
Posted: Aug 20, 2007 12:34 PM
> At the moment I'm refactoring a legacy code base,
> partially written by myself. It works pretty well
> actually, the reason for refactoring is that the
> requirements changed and in order to serve the business
> use cases it needs to be refactored.
> At the time of writing that code, it was actually very
> clever and as said before, it worked pretty well. Looking
> at it now, I just think it's just ugly and I have the
> feeling of refactoring all of it. That's not only the case
> for the code someone else wrote, but also for my own code.
You make a key point here.
I give myself and my colleagues the benefit of the doubt and assume we didn't set out to write ugly code. But what we once thought pretty can become ugly over time. In our inexperience we can write code we think is fine but others, and later ourselves, can find ugly. So that's part of what happens.
The other things that happen are that requirements do change, and technical debt grows.
In technical debt, we deliberately choose the quick and dirty solution for a variety of reasons, knowing that we are incurring later cost. http://www.martinfowler.com/bliki/TechnicalDebt.html
As requirements change, we find that what worked fine before becomes an impediment to further work. We have to refactor and establish new abstractions that solve both the original problems and the new ones.
Just to throw in a metaphor: a fresh coat of paint looks pretty sad after a decade in the sun and rain.