How do you refactor?

refactoring, unit-testing

Solution

- do not refactor anything non-trivial that does not already have unit tests

- write unit tests, then refactor

- refactor small pieces and re-run the tests frequently

- stop refactoring when the code is DRY* clean

* DRY = Don't Repeat Yourself

Problem

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?

Original source

Related problems