Automated Refactoring

1,773 views

Published on

What are code smells and automated refactoring.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,773
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
54
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Automated Refactoring

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

×