Refactoring - An Introduction

8,921 views

Published on

A brief introduction to the agile practice of Refactoring

Published in: Technology, News & Politics
10 Comments
64 Likes
Statistics
Notes
No Downloads
Views
Total views
8,921
On SlideShare
0
From Embeds
0
Number of Embeds
451
Actions
Shares
0
Downloads
0
Comments
10
Likes
64
Embeds 0
No embeds

No notes for slide

Refactoring - An Introduction

  1. 1. Refactoring An Introduction Giorgio Vespucci
  2. 2. “Software must be soft: it has to be easy to change because it will change despite our misguided efforts otherwise.” The Pragmatic Programmers
  3. 3. What we want Robustness Simplicity Softness
  4. 4. What we see Fragility Complexity Rigidity
  5. 5. Unreadable code is…
  6. 6. Hard to modify
  7. 7. Duplicated code is…
  8. 8. Hard to modify
  9. 9. Complex code is…
  10. 10. Hard to modify
  11. 11. Refactored code is...
  12. 12. Easier to understand
  13. 13. Cheaper to modify
  14. 14. Clean code
  15. 15. Better code
  16. 16. Refactored code shows...
  17. 17. Changes to its internal structure
  18. 18. But no change to observable behavior
  19. 19. “So what?”
  20. 20. Try to understand this Java code
  21. 21. java.util.Calendar c =  java.util.Calendar.getInstance(); c.set(2005, java.util.Calendar.NOVEMBER, 20); c.getTime();
  22. 22. Uhm... a Date...
  23. 23. And now this code
  24. 24. october(23,2008);
  25. 25. Hey, mum! It's a Date!
  26. 26. “Any fool can write code that a computer can understand.”
  27. 27. “Good programmers write code that humans can understand.” Martin Fowler - Refactoring
  28. 28. What do we need ?
  29. 29. “If you want to refactor, the essential precondition is having solid tests.” Martin Fowler - Refactoring
  30. 30. Measures matter
  31. 31. Where to start ?
  32. 32. Look at the code
  33. 33. Sniff the code
  34. 34. Does it smell ?
  35. 35. Duupliccateed code? Loooooong method? L a r g e class?
  36. 36. The Refactoring cycle 1) Choose the worst smell 2) Select a refactoring 3) Apply the refactoring 4) Run all the tests
  37. 37. little steps
  38. 38. Great results
  39. 39. Must-have books on Refactoring Refactoring: Improving the Design of Existing Code (Addison-Wesley Object Technology Series) Martin Fowler Refactoring Workbook (Addison-Wesley Object Technology Series) William C. Wake Refactoring to Patterns (Addison-Wesley Signature Series) Joshua Kerievsky
  40. 40. Online resources Smells to refactor http://wiki.java.net/bin/view/People/SmellsToRefactorings Alpha list of refactoring http://www.refactoring.com/catalog/index.html Refactoring Workbook Website http://xp123.com/rwb/ Refactoring to Patterns catalog http://industriallogic.com/xp/refactoring/catalog.html

×