I Refactored Legacy Code for 3 Weeks and Ended Up Reverting Everything
Our company's main service module was 10-year-old code. There were almost no tests, and variable names were things like a and temp2. Anyone could see it needed cleanup, so I thought, "This is the time to do it while we're touching the infrastructure," and drew up a refactoring plan.
The work itself went reasonably well at first. I added some tests, consolidated duplicate logic, and cleaned up dependencies. But after about three weeks, problems started to surface.
- Branching logic that wasn't in the docs kept popping up, turning spec verification into hell
- The product team kept complaining that no feature development could happen during the refactoring period
- QA, of all teams, opposed the release, saying the behavior differed from before
In the end, the team lead said, "Let's revert it for now and focus on features first," so we restored everything. It felt really pointless at the time, but looking back, I think I had the order backwards.
What I learned:
1. Refactoring needs a convincing rationale "separate from feature development"
2. You shouldn't start a major overhaul without test coverage
3. Undocumented branching logic is itself the spec (removing it carelessly causes outages)
Has anyone had a similar experience? Next time, I'm going to approach it more carefully.