Introduction
A large part of software engineering involves not only designing and creating new programs, but also working with existing codebases. Due to a number of reasons, we may need to make changes to the codebase.
There are codebases where changes lead to an increasing number of problems. This is often referred to as legacy code, which the author defines as codebases without tests. The book Working Effectively With Legacy Code discusses how to work with such codebases.
The Problem
Changes in the system can lead to a disruption in the existing functionality of the system. Why then do we need to make changes to the existing system? The book gives 4 reasons.
1.Adding a feature
2.Fixing a bug
3.Improving the design
4.Optimizing resource usage
The challenge when making these changes is to preserve the existing functionality of the system. Preserving the behavior involves some risk. This is because the codebase may have a lot of entanglements and the code to be changed may have some dependencies. Thus changes may result in unwanted changes.
According to the book to mitigate risk, we have to ask 3 questions.
- What changes do we have to make?
- How will we know that we've done them correctly?
- How will we know that we haven't broken anything?
Writing tests can help us with the process of mitigating risks as we know what works.
Solution
To solve the problem described above, the author suggests a legacy code change algorithm of 5 steps. These are:
1.Identify change points
2.Identify test points
3.Break dependencies
4.Write tests
5.Make changes and refactor
The rest of the book contains lots of details on how to execute the steps above.
Conclusion
In a nutshell, the way to deal with legacy codebases is to introduce tests that allow us to understand how the system works,to map out dependencies and where possible break them.The book has lots of details on doing this.
This is a useful and practical book that discusses how to deal with legacy codebases that are too often prevalent in the real world. I recommend this book for experienced and advanced engineers.
The advice given can be useful regardless of the programming languages used.
Top comments (0)