What it is
Inherited code: written long ago, often by other people and for other conditions. It works, but nobody quite remembers why it works that way, and changing it feels risky.
How we use it
We don't rewrite legacy code from scratch without a reason: first we find out what assumptions it relies on, cover it with tests, and only then change it piece by piece.
Where a business runs into legacy code
- A website or bot was inherited from a previous developer, there is no documentation, and it needs new features.
- The system was built five years ago for a hundred customers, and now there are thousands.
- An old module, such as a shopping cart or a delivery calculator, is supposed to move into a new project.
- It runs on a language or CMS version that no longer gets security updates.
How we use it
We take over other people's projects for further development and maintenance, so legacy code is part of everyday work.
- Understand first, change later. We look at what the code silently assumes: data volumes, formats, time zone, limits of external services.
- Cover what matters with tests. Before touching payments or lead forms, we pin down how they behave today with automated tests.
- Change in pieces. Instead of a rewrite from scratch we refactor one part at a time, and every release can be rolled back.
- Reuse with questions. Reusing proven code pays off, but its limitations move along with it.
The textbook example of reuse without checking is the Ariane 5 rocket, lost in 1996 because flight software from the previous rocket met numbers it was never designed for. More on that in integer overflow.
Common problems
- "If it works, don't touch it." Until a change is needed or a security update comes out, and the people who knew the code are gone.
- Rewrite everything. It sounds tempting, but along with the old code you throw away years of fixed bugs. The new version often steps on the same rakes.
- Hidden assumptions. "An order never has more than a thousand items", "the server is always in our time zone": nothing in the code says so, yet everything depends on it.