Legacy Code Cookbook

Make Tests Independent
Recipe: Squeezing Juice out of Over-ripe Tests
While any bug or change would cause one test to fail, many changes cause unrelated tests to fail. This happens because each test is testing too much. Learn how to squeeze each test done so that it only has one reason to fail.

Start Fixing a God Class
Recipe: Converting the God Classes’ Pawns to Work Against It
It seems like fixing a God Class requires taking responsibilities off of it. Often that is too hard, because the God Class is surrounded by procedures that lock it in place. Learn how to convert these pawns to your side so that they can help you remove responsibilities later.

Refactor Databases
Recipe: Fixing Databases with Lego
Bad database schemata cause story delays and generate bugs. The common ways to fix schemata take a long time and interrupt story work. Learn how to change schemata with simple and uniform transformations.

Port Between Technologies
Recipe: Creating and Shipping a Chimera
Migrating between technologies is hard. The common approach is to replace the old technology with the new one. Learn how to incrementally change the technology without disrupting your feature progress.

Test Interactions Between Third Party Services
Recipe: Isolating Dependencies with with Ports & Adapters
Verifying integration with a third party service is hard. The common solution is to write end-to-end integration tests. Learn how to create a different kind of integration test that won’t break with unrelated code changes.

Split a God Class
Recipe: Use Data to Split a God Class
It is hard to split responsibilities out of a God Class because the class is so large and complex. It is difficult to identify the many responsibilities and which methods perform which responsibilities. Learn how to use data to mechanically identify responsibilities without needing to understand the God Class.

DevOps #1: Automate a Manual Process
Recipe: Discover and Automate Manual Processes
Automating manual builds, deploys, or other processes is hard. They rely on specialized knowledge and individual common sense. Others don’t know how to perform the process and the experts do details but forget to automate them. Learn to use checklists to incrementally discover and automate any manual process.

DevOps #2: Enable Unit Testing
Recipe: Make Code Testable Before Testing It
Some code is hard to unit test. But integration tests will cause our pipeline to be constantly broken and mocks will cause it to miss bugs. The solution is to refactor the code to be easy to test. Learn 5 common design flaws and how to fix them to make your code easy to test.