Something I've been reflecting on lately in my role as a professional software developer is that much more time is spent maintaining existing code than there is time spent writing new code. Despite this the vast majority of learning materials currently out there has a focus on writing new code. There's a distinct lack of quality materials  about code maintenence which is quite worrying when you consider that:
Repairing and improving old code is harder than writing new code.
This set of tutorials is aimed at helping you learn the skills involved in repairing and improving existing code. To do this I think the most effective approach is to get samples of real code and show the improvement process as it happens.
Many tutorials that deal with fixing code have a somewhat contrived feel to them. I know that if I try to come up with examples of code to show refactoring techniques I have a bias towards making clean code that has one obvious problem. While this might be good for showing the problems with a particular isolated concept it doesn't really get to the core of why refactoring really bad production code is so challenging. Generally speaking one of the main skills when repairing old code is spotting the problems in the first place. When you are faced with poor quality code that lacks structure a big part of the battle is figuring out the intent of the code. This can be extra difficult if the author didn't know what they were trying to achieve or if they were faced by continually changing project requirements. Additionally you might not have the luxury of being able to ask the author of the code for clarification.
Part of the reason old code is hard to fix is because code is easier to write than it is to read. When you are faced with poor quality codebases this problem is amplified. And if this wasn't already enough you might be faced with these additional challenges:
- The code might not have documentation at all or worse might have documentation that is inconsistent with the actual code.
- There might be no unit tests.
- There may be different authors and coding styles. The quality of the code might be great in some places and terrible in others.
Newly written code from inexperienced programmers is often really good material for this format of tutorial as there are frequently issues the author was completely unaware of, I have some of my old snippets of code lying around that I'm going to hopefully tackle in some of these code repair articles. Once I get some more time I would like to open this up to reader submissions. If people send in great examples of messy code that was deployed that could lead to some really good articles, get in contact with me to discuss more!
List of articles
|||While there's not a ton of resource out there there are a few I would recommend. "Working effectively with legacy code" by Feathers is a great book. I would recommend it if for no other reason than the explanation of "seams" and how you can use them to refactor code.|