Your SlideShare is downloading. ×
0
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Refactoring
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Refactoring

7,190

Published on

Presentation from "Anonymous Developers Club" gathering in Kiev on "Refactoring" topic

Presentation from "Anonymous Developers Club" gathering in Kiev on "Refactoring" topic

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

No Downloads
Views
Total Views
7,190
On Slideshare
0
From Embeds
0
Number of Embeds
29
Actions
Shares
0
Downloads
3
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • We need to realize that software must be soft: it has to be easy to change because it will change despite our misguided efforts otherwise.
  • • Make a small change (a single refactoring)• Run all the tests to ensure everything stillworks• If everything works, move on to the nextrefactoring• If not, fix the problem, or undo the change,so you still have a working system
  • Any time you find that you can improve the design of existing codeYou detect a code that smellsAfter static analysis
  • Any time you find that you can improve the design of existing codeYou detect a code that smellsAfter static analysis
  • Transcript

    • 1. REFACTORING
      XP Injection
      http://xpinjection.com
    • 2. Do You Know Your Code?
    • 3. Developer Golden Rule
      Any fool can write code that a computer can understand
    • 4. Good Developer Golden Rule
      Any fool can write code that a computer can understand
      Good programmers write code that humans can understand
    • 5. Why Fix What is Not Broken?
    • 6. If the Code is Hard to Understand
      Hard to maintain
      Hard to improve
      Hard to work with evolutionary design
      More expensive
    • 7. What is Refactoring?
      A series of small steps, each of which changes the program’s internal structure without changing its external behavior - Martin Fowler
      Verify no change in external behavior by
      Testing
      Using the right tool (IDE)
      Formal code analysis by tool
      Code review or pair programming
      Being very, very careful
    • 8. Prerequisites for Success
      Safety net
      Everybody agreed “Collective code ownership”
      Common understanding of refactoring methods
      Supportive environment
      Powerful IDE
    • 9. Refactoring Cycle
      Find smell
      Select
      refactoring
      Apply
      refactoring
      Run
      all tests
    • 10. 3 Ways to Start
    • 11. Find Something to Improve
    • 12. Make Static Analysis
    • 13. Find Smell
    • 14. How to Find Smell
    • 15. Smells
    • 16. Main Goals
      Organizing data
      Composing methods
      Making methods calls simpler
      Moving features between objects
      Simplifying conditional expression
      Dealing with generalizations
    • 17. Operations Associated with Refactoring
      Replace
      Extract
      Move
      Change
      Introduce
      Remove
      Pull
      Consolidate
      Push
      Inline
      Add
    • 18. When to Refactor?
      When add new functionality
      Refactor existing code until you understand it
      Refactor the design to make it simple to add
      When try to find bugs
      Refactor to understand the code
      During code reviews
      Immediate effect of code review
      Allows for higher level suggestions
    • 19. Key Elementsof Refactoring
      Simplifying complex statements
      Abstracting common solutions into reusable code
      Removal of duplicate code
    • 20. Refactoring Techniques
    • 21. 6 Techniques in Action
    • 22. Extract Method
      void printOwing() {
      printBanner();
      //print details
      System.out.println("name: " + _name);
      System.out.println("amount " + getOutstanding());
      }
      void printOwing() {
      printBanner();
      printDetails(getOutstanding());
      }
      void printDetails (double outstanding) {
      System.out.println("name: " + name);
      System.out.println("amount " + outstanding);
      }
    • 23. Extract Super Class
    • 24. Decompose Conditional
      if (date.before (SUMMER_START) ||
      date.after(SUMMER_END)) {
      charge = quantity * winterRate+ serviceCharge;
      } else {
      charge = quantity * summerRate;
      }
      if (notSummer(date)) {
      charge = winterCharge(quantity);
      } else {
      charge = summerCharge (quantity);
      }
    • 25. Replace Error Code with Exception
      boolean withdraw(int amount) {
      if (amount > balance)
      return false;
      else {
      balance -= amount;
      return true;
      }
      }
      void withdraw(int amount) throws BalanceException {
      if (amount > balance) throw new BalanceException();
      balance -= amount;
      }
    • 26. Replace Exception with Test
      double getValueForPeriod (int period) {
      try {
      return values[period];
      } catch (ArrayIndexOutOfBoundsException e) {
      return 0;
      }
      }
      double getValueForPeriod (int period) {
      return period >= values.length ? 0 : values[period];
      }
    • 27. Parameterize Method
    • 28. Good Design Principles
      DRY
      KISS
      YAGNI
    • 29. No Silver Bullet
      Needs lots of practice
      Requires discipline
      Continuous usage
      Little steps
    • 30. Little steps – huge results
    • 31. You Need to Pay Technical Debt
    • 32. Refactoring Benefits
      More readable code
      Easier maintenance
      Code reuse
      Easier to add new code
      Improved design
      Better understanding
      Speeding knowledge
      Easier to test
      Minimize duplication 
    • 33. Live Demo
    • 34. Questions?

    ×