What is legacy code? I was asked this question in an interview for a contract once. I answered that all code, once written, is immediately legacy code. I got that contract.
I still believe this to be the case. Any developer worth their salt never stops learning. This means yesterday’s code is inevitably not as good as today’s code. The code you wrote yesterday is also likely to differ from how you’d write the same code today.
Who would be affected by our code becoming legacy? Any future developer, obviously. But our future self, as well. When I was less experienced, I often wrote unfriendly legacy code. When I’d revisit the same code a few months later, I’d have no idea what I was thinking when I wrote the code. I could only guess what it was doing.
Why does it matter? It matters because it tells us how to approach writing better code. If know our code is likely to be legacy soon, this would have a few implications.
- Write clear, clean code.
- Write clear tests.
- Keep it simple and short.
However, everybody makes mistakes. Legacy code tends to not be great to work with.
This is why I find Working Effectively with Legacy Code to be such an important book. It gives us the tools we need to deal with legacy code when it’s not written with care.
So, in short. Write your code with care. Imagine you’re writing it for your future self, because you likely are. And share the knowledge, because any developer’s code could be your legacy code tomorrow.
* In the picture: Margaret Hamilton, lead software designer of the Apollo project, standing next to its software listing. Courtesy of MIT Museum. Imagine working on that code base! Colorized using the Image Colorization API | DeepAI
I may get commissions for purchases made through links in this post.