R – How to refactor

refactoringunit testing

I was wondering how other developers begin refactoring. What is your first step? How this process (refactoring) differ if you refactor code which is not yours? Do you write tests while refactoring?

Best Answer

  1. do not refactor anything non-trivial that does not already have unit tests
  2. write unit tests, then refactor
  3. refactor small pieces and re-run the tests frequently
  4. stop refactoring when the code is DRY* clean

* DRY = Don't Repeat Yourself

Related Topic