The Spirit of Refactoring - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

The Spirit of Refactoring

Description:

Project will never be in the ideal state (and even if it were, it ... Extract Method. public Object m() { m1(); m2(); public Object m1() { blah1; blah2; ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 15
Provided by: erica55
Category:

less

Transcript and Presenter's Notes

Title: The Spirit of Refactoring


1
The Spirit of Refactoring
  • Eric Allen
  • Rice University

2
XP and Refactoring
  • Collective code ownership enables refactoring
  • Unit tests enable refactoring
  • Non-fixed deadlines enable refactoring
  • Pair programming enables refactoring

3
Perpetual Refactoring is Essential to a Projects
Continuation
  • Not all code will be good code
  • Project will never be in the ideal state (and
    even if it were, it wouldnt last long)
  • Refactoring prevents code from collapsing under
    its own weight

4
Refactoring and Coding Standards
  • Coding standards are arbitrary
  • Discussing where to put braces is not science
  • A common coding standard prevents waste of
    productivity

5
A Simple Refactoring
  • public int i
  • gt
  • private final int i

6
Wont that break the code?
  • No the type checker wont let it break
  • If the type checker signals errors, you will get
    a list of all places in your code that youd have
    to fix to keep the refactoring
  • Type checker as refactoring aid

7
Another Simple Refactoring
  • public int VERYBADNAME
  • gt
  • public int muchBetterName

8
Can that break the code?
  • Yes! Accidental shadowing is a problem
  • public void m()
  • int veryGoodName
  • VERYBADNAME

9
Accidental Shadowing May Not Signal an Error
  • public class C1
  • int veryGoodName
  • public class C2
  • int VERYBADNAME
  • veryGoodName

10
Unshadowing is Also a Problem
  • public class C1
  • int VERYBADNAME
  • public class C2
  • int VERYBADNAME
  • VERYBADNAME

11
Automated Refactoring Tools
  • Tools help ensure that the refactoring is done
    correctly (provided the tool is correct)
  • IDEA has the fullest set of refactorings, but it
    only works for non-generic Java
  • CodeGuide supports some refactorings

12
Extract Method
  • public Object m()
  • blah1
  • blah2
  • blah3
  • blah4
  • gt

13
Extract Method
  • public Object m()
  • m1()
  • m2()
  • public Object m1() blah1 blah2
  • public Object m2() blah3 blah4

14
Other refactorings
  • Make methods/classes/fields final (advantage?)
  • Move methods into a superclass
  • Push methods into subclasses
  • What else?
Write a Comment
User Comments (0)
About PowerShow.com