Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Refactoring

Emma
May 25, 2012

 Refactoring

What refactoring is, when to refactor, when not to refactor, list of code smells

Emma

May 25, 2012
Tweet

More Decks by Emma

Other Decks in Programming

Transcript

  1. "A change to the system that leaves its behavior unchanged,

    but enhances some nonfunctional quality – simplicity, flexibility, understandability, performance" Kent Beck, Extreme Programming Explained
  2. "A change made to the internal structure of software to

    make it easier to understand and cheaper to modify without changing its observable behavior" Martin Fowler, Refactoring
  3. 1. Make sure your tests pass 2. Find some code

    that “smells” 3. Determine how to simplify this code 4. Make the simplifications 5. Run tests to ensure things still work correctly 6. Repeat the simplify/test cycle until the smell is gone
  4. When you add functionality When you learn something about the

    code When you fix a bug When the code smells
  5. “Here’s a guideline Don Roberts gave me: The first time

    you do something, you just do it. The second time you do something similar, you wince at the duplication, but you do the duplicate thing anyway. The third time you do something similar, you refactor.” The Three Rule, Marting Fowler
  6. When the tests aren’t passing When you should just rewrite

    the code When you have impending deadlines
  7. “The other time you should avoid refactoring is when you

    are close to a deadline. At that point the productivity gain from refactoring would appear after the deadline and thus be too late” Marting Fowler
  8. Indicators that something may be wrong in the code Can

    occur both in production code and test code