Sunday, October 24, 2010

Refactoring pitfalls

Here are some things I found that go wrong during refactoring, or reasons why refactoring is not as easy as it could be:
  • If you have a large enough project, iteration times tend to be long
    • Compilation times are long
    • Startup / loading times are long
    • Running tests takes a long time
  • Refactoring in small steps is difficult, since you either
    • End up spending a long time retesting each iteration, or
    • Try to squeeze in several rounds of refactoring in one sweep, which decreases turnaround time, but increases risk and testing time.
  • The number of test cases is too large and not all tests are (even in principle) automatable. 
    • Corner cases are not always obvious and the effect your refactoring will have is not always clear
The combination of long iteration times and large number of test cases can make refactoring code very costly (and believe me I've paid the price). You end up doing it in large sweeps, while adding new features at the same time, after which everything is broken and you need to do a whole suite of tests needs to be designed (or redesigned). I've had refactorings that took between 1 week to 1 month, and I regretted starting them in the first place. I was happy about the end result, and probably in the long run it still paid off, but the time and the energy it took to get the system back on track was enormous, and I'm still looking for better ways. Suggestions are welcome.

    No comments:

    Post a Comment