Hello Reader 👋 I hope you are doing well today! I recently finished reading “Refactoring at Scale” by Maude Lemaire, while on a nice family trip to Toronto, Canada 🍁 Honestly, I found it quite good. It's packed with interesting insights and good advice built from concrete real-life experiences. It has become one of the few books I would recommend to someone dealing with a huge codebase, dozens of engineers constantly molding it, and pressure to keep delivering business value to customers. Maude Lemaire wrote this book based on her own experience at Slack, where she led refactoring projects to keep the cost of adding new features reasonable as they grew. Today, I would like to share my notes with you! P.S. here’s a shareable link to this article if you want to save it for later or share it with a friend. Refactoring, but at scale“At scale” is the issue. When a change affects a substantial part of your codebase, there are too many subtle interactions to anticipate the effects it might have. Yet, refactoring is particularly valuable to increase developers’ productivity and ease bug detection. Good refactorings make it cheaper to add new features and reduce the risk of introducing regression—thus, you can add more value to your product, faster. But refactoring is changing the structure of the code. Thus, there is a risk of breaking things. What can help?
Oh and if you don’t have automated tests, Approval Testing will help you quickly set up an anti-regression safety net 😉 When to refactor?
When NOT to refactor?
Planning large-scale refactoringsIs there something your team would like to clean up if they had time? Great. Now let’s start with a plan! A plan will help you carry on a large-scale refactoring, and can help you convince the stakeholders about such a project. It’s not just a vague complaint about code quality anymore. Maude suggests the following steps:
Here’s an example of what a plan would look like, from Maude:
Beware of scope creep. It’s very easy and tempting to “do that while we are at it”. You are more likely to succeed if you keep a sharp focus. Postpone that suggestion until after the refactoring is complete. Chances are the refactoring will make such change easier to do. Getting buy-in from your managerThis may be tough. I already wrote about arguments that may work and how you can use git logs to build a case for such a project. After all, why can’t the company keep handling this tech debt like it’s already doing? What’s the value for the customer? How would they convince their own manager about it? Maude shares a few tips to help you with these discussions:
In my experience, this is not just about legacy code, but about legacy culture. If you are in a position of leadership, you can foster these initiatives by making refactoring work visible. For instance:
Building the right teamMaude gives a lot of advice about setting up a team that would address a large-scale refactoring project. What resonated the most with me are:
Executing a large-scale refactoringIf your team is not already communicating effectively on a frequent basis, maybe you should consider delaying a large refactoring project.
— Maude Lemaire, “Refactoring at Scale”
Communication is key. Especially at scale. Your team is connected to others through the codebase you are evolving. Changes can have unexpected consequences. Agendas may conflict. There are things you can do to help your team succeed in such a project:
It’s also a good idea to encourage knowledge sharing within your team. Pairing is one way to do it. Encourage it, but don’t make it mandatory—make them feel the benefits of pairing, don’t force it upon them. Rollout strategies: dark vs. light modeMaude reports that she had good success with what was known at Slack as “Dark Mode” and “Light Mode” rollouts. The idea is to deliver large-scale changes in the following steps:
This allows you to collect feedback as soon as possible. This feedback will help you adjust to reality—no plan can prepare you for that. As your confidence increases, you progressively roll it out. The downside is that the codebase will be in an intermediate state for a while. But that’s what it is with large-scale refactorings. Just make sure to push the project across the finish line. Don’t let both implementations live forever in the code. Cleanup your feature flags 😉 ConclusionThere are many details that I haven’t mentioned here. You can tell Maude Lemaire knows about her topic and sprinkles tons of excellent advice that can resonate with you throughout the book. Should you fix a bug that you come across? How would you make your refactor stick? How do you manage the shortcuts you may take during the refactoring? Etc. The last part of the book is dedicated to 2 concrete use cases. Two stories from the trenches at Slack, where Maude shares what went well… and what didn’t:
So yeah, “Refactoring at Scale” is a book I would recommend. It’s rooted in the reality of growing companies that need to go fast while having a legacy to carry on. Both a blessing and a challenge. If that’s your reality, then you will get the most from this book 👍 Until next time, take care! |
Piles of Tech Debt, no tests, no docs, short deadlines… But you are not alone! Join me and get regular tips, tricks, and experiments to turn unfriendly codebases into insightful ones 💡
Hello Reader 👋 I hope you are doing well today! Do you often find yourself fighting with the intricacies of legacy code or navigating through convoluted programming structures? In his popular “Refactoring” book, Martin Fowler collects an impressive catalog of moves that can transform the way you approach code maintenance and evolution. If you haven’t read it and are unsure what to expect, I’ve written down a high-level summary of what you will find here. Hopefully, that gives you a better...
Hello Reader 👋 I hope you are doing well today! If you had a magic wand, what would you do with the tangled legacy codebase you are dealing with? For many developers, the answer will go along the lines of: Kill it with Fire!!1!Let’s rewrite the whole thing on a modern stack. Hopefully, Marianne Bellotti, the author of the book with such a provocative title, has better options for you. I've read it cover to cover and I will share with you my personal highlights here. P.S. here’s a shareable...
Hello Reader 👋 I hope you are doing well today! For the past few weeks, I have been reading different studies about developers and how they interact with unfamiliar codebases at work. Today, I would like to share one that I found particularly insightful… and painfully close to my own experience. The title: “It’s Like Coding in the Dark”: The need for learning cultures within coding teams— Catherine Hicks, Catharsis Consulting (2022) PDF source If you prefer to read that online, I wrote an...