Webcast (in Italian)
Legacy code is simply code without tests.The goal of every competent software developer is to create designs that tolerate change! This is why it is critical to learn how to confidently make changes in any code base.
Preserving existing behaviour is one of the largest challenges in software development.The three main questions to ask are:
Legacy Code Dilemma
When we change code, we should have tests in place. To put tests in place, we often have to change code.
It is important to know what can be affected by the changes we are making!Effect Sketching is a useful technique that can be used to answer this question. The idea is to create a little graph that shows the effect of your changes. Navigation tools like ReSharper can help you identify all usages of a particular piece of code. However, if your class has a superclass or subclasses pay attention because there might be other clients that you haven't considered.
Working in legacy code is surgery, and doctors never operate alone.Consider reading the book Pair Programming Illuminated. Refactoring
The best way to get better at finding responsibilities is to read more books about design patterns and in particular to read more code.
Programming is the art of doing one thing at a time!Ask your partner to challenge you constantly asking: What are you doing?
Remove duplication as much as possible!You end up with very small focused methods. The goal is to have orthogonality in the system. Your system is orthogonal when there is only one place you have to go to make a change. Removing duplication often reveals design.
Remember, code is your house, and you have to live in it.Rename Class is the most powerful refactoring. It changes the way people see code and lets them notice possibilities that they might not have considered before.
A method should be a command or a query, but not both. A command is a method that can modify the state of the object but that doesn't return a value. A query is a method that returns a value but that does not modify the object.Extract Method is a core technique for working with legacy code. You can use it to extract duplication, separate responsibilities, and break down long methods. It is also recommended to extract methods in a bottom up approach. Extract small pieces first!