Legacy refactor: start by playing Rambo
Grab the bandana before the IDE
You bump into legacy code loaded like a Soviet truck. The temptation is to understand every detail before touching anything. Bad idea. Flip the Rambo switch first:
- Trash whatever's lying around: dead features, flags no one reads, forgotten libs. If nobody uses it, it's ballast.
- Delete esoteric helpers: a util run once for a manual test in 2018? Gone.
- Kill zombie routes: an endpoint with no metrics or logs is suspicious. Cut it and see who screams.
Worst case, Git brings back whatever you tossed. Archaeology can wait.
Purge first, understand later
The smaller the perimeter, the more your brain breathes. By shrinking the scope, you immediately spot what is truly used:
- Trace the calls:
rgordepcruisewill quickly tell you if a dependency still matters. Zero hits? Uninstall it. - Check events and jobs: a queue consumed by nobody or a silent cron are alarm bells. How do you refactor a ghost?
- Observe runtime: run the app without the removed modules. You'll see real errors, not imaginary ones.
Obsolete libraries: keep or rewrite?
An ancient dependency for a single function? You didn't sign up to haul moment.js to 2025 just to format one Date. Ask yourself:
- How many calls are there? Three usages? Recode the function in ten lines and drop a dependency.
- What's the upgrade cost? If the lib forces six major migrations, it's probably faster to replace it.
- Is there a native alternative? Often yes. Standard APIs cover 80% of needs; the rest you can code cleanly.
The more you cut, the clearer the rest becomes. And if you really deleted a vital piece, Git can resurrect it in under thirty seconds.
Rambo first, architect after
This "brute force" phase isn't the final refactor. It's groundwork:
- You clarify the perimeter: less fat, more essentials.
- You reduce risk: fewer dependencies, fewer bug vectors.
- You speed up the next steps: the real rebuild (tests, design, decoupling) becomes doable.
So yes, put on the red headband and clean with rapid fire. Only after that do you pick up the blueprints, design an architecture, and code like an adult. Git keeps the souvenirs; you keep your sanity.