October 24, 2014
Refactoring Is Dead (Hard)Jason Yip tweets jokingly that he's waiting for someone to write "Refactoring Is Dead".
Well, here it is.
The "TDD is Dead" meme started with a blog post with that clickbaity title, arguing that folk are doing TDD wrong. So it seems in that same spirit to argue that "refactoring is dead" for a similar reason.
But that would be innacurate. It would be more accurate to say that refactoring was never really alive in the first place.
As a practice, refactoring has never really taken off. It's one of those things that many claim to have done on the CVs, but few actually ever have, safe in the knowledge that the person interviewing them is probably lying about their refactoring experience, too.
Pair with 100 Agile developers, and if you're lucky you may find a handful who even understand what refactoring really is. having paired with thousands of developers over the years, I know that perhaps 1% of us can actually do it for real.
And the reason for this is simple. Refactoring, as a skill and a discipline, takes a lot of time and study and practice to get competent at. It's like swimming - it exercises all of the muscles developers use. There has to be unit tests. You have to have an eye for code quality problems ("code smells"). You have to understand the mechanics of each refactoring, which requires the ability to reason about code in a way that's more rigorous than most of us are used to. And, once you get past the basics to the good and most useful stuff, it requires the ability to think several refactorings ahead - like a chess player - so that you can restructure and manipulate complex code into the desired forms. If TDD is riding a bicycle, then refactoring is flying a helicopter.
In summary, refactoring is hard. Dead hard.
UPDATE: Yes, I know that TDD involves refactoring. But I also know that a majority of developers who say they do TDD do little or no refactoring as part of it. And the ones who do are doing very simple refactorings. Legacy code is a whole different ball of wax.
Posted 6 years, 1 month ago on October 24, 2014