vicmaster
5/1/2015 - 4:29 PM

Refactoring Tips

Refactoring Tips

Refactoring Tips

  • When you find you have to add a feature to a program, and the program's code is not structured in a convenient way to add the feature, first refactor the program to make it easy to add the feature, then add the feature.

  • Before you start refactoring, check that you have a solid suite of tests. These test must be self-checking

  • Refactoring changes the programs in small steps. If you make a mistake, it is easy to find the bug.

  • Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

  • Refactoring (noun): A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.

  • Refactor (verb): To restructure software by applying a series of refactorings without changing its observable behavior.

  • Three strikes and you refactor.

  • Don't publish interfaces prematurely. Modify your code ownership policies to smooth refactoring.

  • It is better to write and run incomplete tests than not to run complete tests.

  • Think of the boundary conditions under which things might go wrong and concentrate your tests there.

  • Don't forget to test that exceptions are raised when things are expected to go wrong.

  • Don't let the fear that testing can't catch all bugs stop you from writing the tests that will catch most bugs.

  • Comments often identify pieces of a method that can be extracted. Additionally the comment itself can be a potential name for the extracted method.