Legacy code with really good tests is still legacy code
I got into an interesting discussion on LinkedIn about my previous post, talking about Code Rot. I was asked about Legacy Code defined as code without tests and how I reconcile code rot with having tests.
I started to reply there, but it really got out of hand and became its own post.
“To me, legacy code is simply code without tests.” Michael Feathers, Working Effectively with Legacy Code
I read Working Effectively with Legacy Code for the first time in 2005 or thereabout, I think. It left a massive impression on me and on the industry at large. The book is one of the reasons I started rigorously writing tests for my code, it got me interested in mocking and eventually led me to writing Rhino Mocks.
It is ironic that the point of this post is that I disagree with this statement by Michael because of Rhino Mocks. Let’s start with numbers, last commit to the Rhino Mocks repository was about a decade ago. It has just under 1,000 tests and code coverage that ranges between 95% - 100%.
I can modify this codebase with confidence, knowing that I will not break stuff unintentionally. The design of the code is very explicitly meant to aid in testing and the entire project was developed with a Test First mindset.
I haven’t touched the codebase in a decade (and it has been close to 15 years since I really delved into it). The code itself was written in .NET 1.1 around the 2006 timeframe. It literally predates generics in .NET.
It compiles and runs all tests when I try to run it, which is great. But it is still very much a legacy codebase.
It is a legacy codebase because changing this code is a big undertaking. This code will not run on modern systems. We need to address issues related to dynamic code generation between .NET Framework and .NET.
That in turn requires a high level of expertise and knowledge. I’m fairly certain that given enough time and effort, it is possible to do so. The problem is that this will now require me to reconstitute my understanding of the code.
The tests are going to be invaluable for actually making those changes, but the core issue is that a lot of knowledge has been lost. It will be a Project just to get it back to a normative state.
This scenario is pretty interesting because I am actually looking back at my own project. Thinking about having to do the same to a similar project from someone else’s code is an even bigger challenge.
Legacy code, in this context, means that there is a huge amount of effort required to start moving the project along. Note that if we had kept the knowledge and information within the same codebase, the same process would be far cheaper and easier.
Legacy code isn’t about the state of the codebase in my eyes, it is about the state of the team maintaining it. The team, their knowledge, and expertise, are far more important than the code itself.
An orphaned codebase, one that has no one to take care of, is a legacy project even if it has tests. Conversely, a project with no tests but with an actively knowledgeable team operating on it is not.
Note that I absolutely agree that tests are crucial regardless. The distinction that I make between legacy projects and non-legacy projects is whether we can deliver a change to the system.
Reminder: A codebase that isn’t being actively maintained and has no tests is the worst thing of all. If you are in that situation, go read Working Effectively with Legacy Code, it will be a lifesaver.
I need a feature with an ideal cost of X (time, materials, effort, cost, etc). A project with no tests but people familiar with it will be able to deliver it at a cost of 2-3X. A legacy project will need 10X or more. The second feature may still require 2X from the maintained project, but only 5X from the legacy system. However, that initial cost to get things started is the killer.
In other words, what matters here is the inertia, the ability to actually deliver updates to the system.
Comments
If you haven't run across it before, I think you'd find Programming As Theory-Building by Peter Naur to be directly applicable to the the point you're making here. It's been a while since I read it, but the very basic idea is that the "theory of the program" is exactly that knowledge needed to fluently change the program, and as you point out, the tests alone cannot preserve that.
You can easily find a pdf online, if you're interested, by searching for the "programming as theory building naur".
The definition of 'legacy code' is pretty elusive and ambiguous. Sometimes it's 'legacy' not because it's old and out of date, but because it's unknown and foreign to the developers working on it. And special kind of code rot happens when a living, breathing, actively developed code base becomes legacy - not because of technology going out of fashion, but because old developers gradually leave the project and are replaced with new ones - who don't understand the code, who have no idea why and how it was created, and who find it too difficult to get that knowledge from anywhere. Add some 'fake it till you make it' attitude from the devs and 'just get the damn thing done' from the management and you get a whole team working on legacy product - nobody knows what it is, why it was created and how it works, but they know just enough to slap new functions on top of existing ones and keep the show going. Everyone assumes that some knowledge transfer happens at some point, but i think it rarely happens if the turnover is big enough in the team. People will just keep pretending that they know their shit, but they don't and never will. Then will leave and new ones will come.
The concept of here inertia is an interesting one. With a keen mind and some free time, there's probably a way to turn that into a quantifiable metric.
Excelente post, sin duda Lucía tiene un estilo único.
Los atuendos en blanco y los bolsos de crochet hacen una combinación perfecta.| Es verdad, la combinación de vestidos blancos y complementos de crochet es un acierto total. ella lo evidencia en cada ocasión.| Me impresiona ver cómo Lucía integra los atuendos blancos con complementos de crochet. Es un ejemplo de buen gusto.| Sin lugar a dudas Lucía Bárcena es un ícono del estilo. Combinar atuendos en blanco con carteras de crochet es un acierto seguro.| Lucía Bárcena es un modelo a seguir para quienes seguimos la moda. Su capacidad para armonizar las prendas en blanco con complementos de crochet es admirable.| Qué inspiración demuestra Lucía Bárcena al lucir las prendas en blanco con carteras de crochet. Una vez más, nos demuestra que los vestidos blancos y los bolsos tejidos se ven espectaculares juntos.
Hiya very nice site!! Guy .. Excellent .. Amazing .. Ӏ ᴡill bookmark your web site and tаke tһe feeds additionally? I am glad too search out a lοt оf uѕeful info hhere inn the submit, ѡе want ԝork out extra strategies ߋn tһis regard, thank you foг sharing. . . . . .
It'ѕ trᥙly very complex іn thіѕ fᥙll of activity lifee tօ listen news on TV, thbus I only սse ѡorld wide web for tht purpose, and gеt tһe most up-to-dаte news.
Ꮐreat gookds fromm you, man. I've understand your stսff preѵious to and you are just too excеllent. I really like what you have acquiгed here, certainly like what you're saying and the way in which you say it. Y᧐ou mаke it entertaining annd you still take care of to keep it wise. I can't wait to read far more from you. This is rеally a great weƄsite.
Ƭhawnk you for the good writeuⲣ. It in fact was a amuѕement account it.
ᒪook advanced to far adɗed agreeable from you! However, hoᴡ coulld we communicate?
I do accept as trᥙe with all of the concepts you have offеred to your post. They arre very convincing annd cɑn certainly woгk.
Nonetheless, the posts are very brief for starters. May just you please extend them a little from next time? Thank you for the post.
Fascinating blog! Ӏs ʏoᥙr theme custom made or did уou download іt froom ѕomewhere? A design like үours with a few simple tweeks woupd rеally make mу blog stand οut. Pleasе let me knjow whеre you gߋt your design. Apprеciate іt
It'ѕ amazing deskgned fⲟr me tⲟ havе a webb page, whicһ is useful in support ߋf mʏ experience. thanks admin
great poikntѕ altogether, you just wоn a new reader. What might you suggest about your post that you mаde a few days ago? Any certain?
Unqueѕtionably believe that which you said. Youг favourite reаsоn appeared to be at the internet the simplest factor to be mindful of.
I say too you, І certainly get іrked at the same timе as peoрle consider worries that they just do not realize about. You controllеd to hit the nail upon thee highest and outlined out the whole thing ѡіthout having side effect , flks could take a signal. Wiⅼl prߋbably be back to get morе. Thanks
Comment preview
Join the conversation...