Hacktakes · Edition 17
Hacktakes · Edition 17 · August 3, 2026

The Termite Principle of Legacy Code

Because rewriting legacy code from scratch is corporate suicide, engineers must use deterministic tools to incrementally port its load-bearing bugs.

By Saul Berger

Sparked by AI migrated legacy COBOL programs to Java, bugs included · discussion

Put the spray down—those are load-bearing bugs!
Put the spray down—those are load-bearing bugs!

Let’s say Mikey the hotshot new Senior Architect starts his job, grabs his complimentary artisanal cold-brew, opens up the company's ten-year-old billing codebase, and immediately starts hyperventilating. It is a terrifying, 500,000-line hairball of nested IF statements, bit-shifts, undocumented stored procedures, and duct tape. There are variables mysteriously named tmp2 and final_FINAL_val. His Architecture Astronaut brain instantly screams that this is an abomination against all known laws of computer science, marches directly into the CEO's office, slams his fist on the mahogany desk, and demands they halt all feature work for the next eighteen months to rewrite the entire thing from scratch in Rust.

Mikey looks at the decade-old while loops and assumes the original developers were a pack of crayon-eating nincompoops who couldn't engineer their way out of a paper bag. He wants to achieve mathematical purity. He wants a clean slate.

He is completely, utterly wrong.

More than two decades ago, in an essay titled Things You Should Never Do, Part I, Joel Spolsky pointed out that Netscape committed corporate suicide by deciding to rewrite their browser from scratch. They threw away years of battle-tested code to build a beautiful, pure architecture, and in doing so, they handed the entire internet browser market to Microsoft on a silver platter for a decade. The idealists in the room always assume that old code is inherently bad code because it looks messy and lacks modern design patterns. But old code has a massive, undeniable advantage over your shiny new whiteboard architecture.

Old code has been used.

It has been dragged through the unforgiving meat-grinder of the real world. Every single one of those horrifying, nested if statements that makes Mikey want to gouge his eyes out is actually the accumulated scar tissue of capitalism. That legacy codebase is the literal, compiled history of every frantic 3:00 AM phone call and panicked Friday night hotfix. These monstrosities are highly specific, completely undocumented business rules dealing with insane edge cases that actually happen in production, like a VIP customer whose last name is a single quote, or a leap-year timezone shift that only triggers on a Tuesday in Helsinki. Attempting to "clean up" these anomalies by guessing what the original developer meant is roughly equivalent to disarming a thermonuclear warhead with a pair of plastic tweezers.

Which brings us to a universal reality I like to call The Termite Principle of Legacy Code.

A ten-year-old production codebase is exactly like a 100-year-old plaster ceiling in a dilapidated Victorian house. Picture a simple, MS-Paint style diagram in your head for a second: a visibly sagging ceiling labeled 'Production Billing System'. The only thing keeping that plaster from collapsing directly onto the dining room table is a million microscopic termites physically holding hands.

If you try to exterminate the termites—if you aggressively refactor out the undocumented rounding errors and the bizarre race conditions that somehow cancel each other out in production—the entire house comes down. The system depends on the bugs. The bugs are the load-bearing beams. The naive programmer grabs a can of RAID, thinking he is cleaning things up, completely ignoring the fact that the business relies on that structural integrity to process payroll. The idealist wants to spray the bugs and build a beautiful steel truss, completely ignoring the fact that while the house is being tented, the business is bleeding millions of dollars a day and the competitors are eating your lunch.

So if rewriting from scratch is economic suicide, and the termites are structurally integral to the ceiling, how do you actually modernize a legacy system without going bankrupt?

You use deterministic AST migrators.

Computer scientists have recently been making serious headway on rigid, mathematically sound parsing tools that physically translate the Abstract Syntax Tree of the old codebase into a modern stack. Listen, if your brilliant migration strategy involves feeding your enterprise billing system into a hallucinating LLM that confidently guesses at syntax and invents fictional API endpoints because it read a bad tutorial from 2018, you are playing Russian Roulette with the payroll system. Stop it. Real engineering requires rigid, deterministic compilation that ports the code—and crucially, ports the termites exactly as they are. It scoops up every single grotesque edge case and deposits it safely onto the new foundation. The bugs survive. The business survives.

Naturally, the internet pedants completely missed the point.

If you look at the reaction to this research, you will find Hacker News commenters whining endlessly about the fact that these AST tools currently have a limitation of around 4,000 lines of code per batch, complaining that some bozo on their team once wrote a monolithic class bigger than that before lunch, and lamenting that such a pathetic tool scale could never possibly handle a real enterprise migration because true engineering requires unbounded context windows and infinite gigascale processing pipelines.

Sheeeesh.

(Attention, math geniuses: just sit quietly for a second and let me explain how enterprise microeconomics works.)

A 4kLOC limit is actually a mathematically mandatory survival strategy disguised as a technical shortcoming.

Look at the catastrophic financial risk of mainframe-scale migrations. Look at the IRS Individual Master File, a legendary hairball of assembly code from the Kennedy administration, or the airline IT outages that ground ten thousand flights because someone tried to deploy a monolithic system upgrade all at once. When you are migrating a system that handles billions of dollars in transactions, you do not want to port 500,000 lines of code in a single massive weekend cutover. If you do, and you miss exactly one termite, the entire global logistics network halts, planes fall out of the sky, and angry shareholders start demanding heads on pikes.

You do the math. You break that terrifying ceiling down into tiny, 4kLOC patches. You port those patches bug-for-bug, validating deterministically that every single historical anomaly behaves exactly the same way in the new language as it did in the old one. You migrate the system piece by excruciating piece, keeping the business running and the cash flowing the entire time.

Everything else is commentary.

Anyway, unless you want to bankrupt your company while pursuing architectural purity, stop romanticizing the clean slate. Instead of trying to exterminate the bugs, your actual job is to carefully scoop up the termites, move them to a new foundation without breaking their little hands, and pray. If you can't handle that, go back to building go-carts.

← Back to Edition 17