Automated Refactoring

download Automated Refactoring

If you can't read please download the document

Transcript of Automated Refactoring

  1. 1. Code Smells And Automated Refactoring Janeve George [email_address] Amit Goyal [email_address] Presented By:
  2. 2. Few Instructions
    • It's not a presentation !!!
    • 3. Parking lot
    • 4. Feedback stickies
  3. 5. Flow Of The Session
    • The Problem
    • 6. Code Refactoring
    • 7. Automated Refactoring
    • 8. Code Smells
    • 9. Quiz
    • 10. Refactoring Workshop
  4. 11. Flow Of The Session
    • The Problem
    • Code Refactoring
    • 12. Automated Refactoring
    • 13. Code Smells
    • 14. Quiz
    • 15. Refactoring Workshop
  5. 16. The Problem
  6. 17. Flow Of The Session
    • The Problem
    • 18. Code Refactoring
    • Automated Refactoring
    • 19. Code Smells
    • 20. Quiz
    • 21. Refactoring Workshop
  7. 22. Code Refactoring
    • Series of small steps
    • 23. Change in the internal structure
    • 24. No change in the external behavior
  8. 25. java.util.Calendar c =java.util.Calendar.getInstance(); c.set(2010, java.util.Calendar.APRIL, 25); Date today = c.getTime();
  9. 26. Date today = april(25, 2010);
  10. 27. double getPayAmount() { double result; if (_isDead) { // Get the dead amount result = getAmount1(); } else { if (_isSeparated)) { // Get the separated amount result = getAmount2(); } else { if (_isRetired) { // Get the retired amount result = getAmount3(); } else { // Get the normal amount result = getAmount4(); } } } return result; }
  11. 28. double getPayAmount() { if (_isDead) return deadAmount(); if (_isSeparated) returnseparatedAmount(); if (_isRetired) return retiredAmount(); return normalPayment(); }
  12. 29. Flow Of The Session
    • The Problem
    • 30. Code Refactoring
    • 31. Automated Refactoring
    • Code Smells
    • 32. Quiz
    • 33. Refactoring Workshop
  13. 34. Automated Refactoring
  14. 35. Flow Of The Session
    • The Problem
    • 36. Code Refactoring
    • 37. Automated Refactoring
    • 38. Code Smells
    • Quiz
    • 39. Refactoring Workshop
  15. 40. Code Smells
    • Duplicated Code
    • 41. Long Method
    • 42. Large Class
    • 43. Switch Statements
    • 44. Feature Envy
    • 45. Magic Number
    • 46. Comments
    • 47. Improper Name
    • 48. & Many More....
  16. 49. Duplicate Code
  17. 50. Long Method
  18. 51. Large Class
  19. 52. Switch Statements
  20. 53. Feature Envy
  21. 54. Magic Numbers
  22. 55. Comments
  23. 56. Improper Naming
  24. 57. Flow Of The Session
    • The Problem
    • 58. Code Refactoring
    • 59. Automated Refactoring
    • 60. Code Smells
    • 61. Quiz
    • Refactoring Workshop
  25. 63. if( isSpecialDeal() ) { total = price * 0.95; send(); } else { total = price * 0.98; send(); } Identify code smells in the following code snippet and suggest remedies:
  26. 64. Refactor the following code: int d;//elapsed time in days
  27. 65. What are the remedies to deal with a large class?
  28. 66. Refactoring helps in __________, ___________, __________.
  29. 67. double potentialEnergy(double mass, double height) { return mass * 9.81 * height; } Identify code smells in the following code snippet:
  30. 68. Large class violates _____________ principle.
  31. 69. What are the techniques/remedies to deal with a long method?
  32. 70.
    • make it loosely coupled
    • 71. improve code readability
    • 72. make it simple
    Renaming a method helps to (choose any one option):
  33. 73. Duplicate code violates ___________ principle.
  34. 74. void printOwning(double amount) { printBanner(); //Print details System.out.println("name"+ _name); System.out.println("amount" + amount); } Identify code smells in the following code snippet and suggest remedies:
  35. 75. //Calculate perimeter double temp = 2 * (_height + _width); Refactor the following code:
  36. 76. double disabilityAmount() { if( _seniority < 2 ) return 0; if( _monthsDisabled > 12 ) return 0; if( _isPartTime) return 0; ..... ..... } Refactor the following code:
  37. 77. Flow Of The Session
    • The Problem
    • 78. Code Refactoring
    • 79. Automated Refactoring
    • 80. Code Smells
    • 81. Quiz
    • 82. Refactoring Workshop
  38. 85. References
  39. 86. [email_address] [email_address]