Working on a greenfield project once in a while is nice and liberating. More often though, maintenance of legacy systems is the reality. People define the term "legacy system" differently. A naive - and common - definition is legacy = old. Since the industry evolves so quickly, old must be bad as a consequence. I think there is more to it than that. There are new systems - most of them actually - that can be considered legacy even before they're made.
Systems are built to satisfy requirements. Requirements have the tendency to change often. Ideally a system can be feasibly adapted to these changes. My definition of legacy is simple: when such adapting is not feasible. This can happen for various different reasons: bad internal quality, badly chosen or obsolete technology, compatibility constraints, and a lot more.
The pace systems turning into legacy can be controlled and some improvements can be made even when the damage is already done. Compatibility constraints (like APIs) can be tough to challenge, changing certain technologies may be difficult. Improving internal quality through continuous refactoring is usually available as a viable option. In refactoring, the technical todo is usually the easy part. The hard part is how to do it in the context of development process, especially if new functionality needs to be continuously delivered. In such a scenario, several ideas can come into mind.
One is to make small changes at a time. This approach can be problematic if the development team is not disciplined enough. Bad code is viral and tends to reinfect the already healed parts. Also there are certain types of changes that can't be reasonably split into several smaller changes. A bit more elaborate strategy is called for. An enticing option is to create bubbles: carefully separate a part of the system from the others, refactor the bubble to it's "ideal" state. Eventually bubbles grow, merge and take over the system. This is a most useful approach, and can result in success.
These bubbles have interesting pitfalls though. The anti corruption layer that protects a bubble has its cost. If the bubble is left alone, not nurtured actively, the additional complexity it introduces becomes a burden to the system. In some cases it's worse to live with it than with the problems of original system. Fragmented pieces of hanging refactorings can be expensive.
Showing posts with label refactoring. Show all posts
Showing posts with label refactoring. Show all posts
Wednesday, June 6, 2012
Thursday, May 6, 2010
Why invest in TDD? Refactoring.
I've been asked lately why test-driven development so important. Apparently many teams (or their management) still think of methodical unit testing as an additional luxury expense. "We don't have time for tests", "Test code can't be sold" are common arguments.
Without digging into testing methodology, design considerations and consequences, I'd like to focus on benefits in the broader context of development process. Most modern methods - especially agile - aim to address the problem of code decay. During a software project's life-cycle the code quality deteriorates, and the cost of introducing new features increases significantly. Refactoring is the main means to improve code quality and protect against decay in order to keep development and maintenance costs manageable.
I highly recommend the following book for reading: Refactoring - Improving the Design of Existing Code from Martin Fowler. He discusses this topic in great depth.
Without digging into testing methodology, design considerations and consequences, I'd like to focus on benefits in the broader context of development process. Most modern methods - especially agile - aim to address the problem of code decay. During a software project's life-cycle the code quality deteriorates, and the cost of introducing new features increases significantly. Refactoring is the main means to improve code quality and protect against decay in order to keep development and maintenance costs manageable.
Note: this diagram is an illustration
We can come to the conclusion that continous refactoring should be an organic part of the development process. The main challange is though, non-trivial refactorings are potentially unsafe. Even a carefully done refactoring has potential to breaking functionality. Most developers - rightly - don't do unsafe operations often (otherwise they would sit in front of a debugger all day long without being productive). One of the most important goals of testing is to make refactoring safe: make resulting problems instantly apparent and easy to pinpoint. According to my experience they serve this purpose very well.I highly recommend the following book for reading: Refactoring - Improving the Design of Existing Code from Martin Fowler. He discusses this topic in great depth.
Labels:
agile,
CodeProject,
refactoring,
TDD,
testing
Subscribe to:
Posts (Atom)