1 / 13

Refactoring

Refactoring. An Automated Tool for the Tiger Language Leslie A Hensley hensleyl@papermountain.org. What I’m Going to Show You. An example refactoring The what, why, when, and how of refactoring My project Refactoring resources. public class RefactoringExample {

satya
Download Presentation

Refactoring

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Refactoring An Automated Tool for the Tiger Language Leslie A Hensley hensleyl@papermountain.org

  2. What I’m Going to Show You • An example refactoring • The what, why, when, and how of refactoring • My project • Refactoring resources

  3. public class RefactoringExample { public static void main(String args[]) { if( args.length > 0 ) { String numberString = args[0]; int number = Integer.parseInt( numberString ); String rank; switch( number ) { case 1: rank = "first"; break; case 2: rank = "second"; break; case 3: rank = "third"; break; } System.out.println( "You placed " + rank ); } else { System.out.println( "One parameter is required: 1, 2, or 3" ); } } }

  4. public class RefactoringExample { public static void main(String args[]) { if( args.length > 0 ) { String numberString = args[0]; int number = Integer.parseInt( numberString ); String rank; switch( number ) { case 1: rank = "first"; break; case 2: rank = "second"; break; case 3: rank = "third"; break; } System.out.println( "You placed " + rank ); } else { System.out.println( "One parameter is required: 1, 2, or 3" ); } } }

  5. public class RefactoringExample { public static String calculateRank( String numberString ) { int number = Integer.parseInt( numberString ); String rank; switch( number ) { case 1: rank = "first"; break; case 2: rank = "second"; break; case 3: rank = "third"; break; } } public static void main(String args[]) { if( args.length > 0 ) { String numberString = args[0]; String rank = calculateRank( numberString ); System.out.println( "You placed " + rank ); } else { System.out.println( "One parameter is required: 1, 2, or 3" ); } } }

  6. What is Refactoring • Refactoring(noun): a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior. • Refactor(verb): to restructure software by applying a series of refactorings without changing its observable behavior.

  7. The result of this is that the system is always as simple as we can make it, which means we can understand it better, which means we can change it more rapidly while keeping it reliable. Try it, you'll like it ... --Ron Jeffries

  8. Why Should You Refactor • Refactoring improves the design of software. • Refactoring makes software easier to understand. • Refactoring helps you find bugs. • Refactoring helps you program faster.

  9. When Should You Refactor • Refactor when you add duplicate code. • Refactor when you add functionality. • Refactor when you need to fix a bug. • Refactor as you do a code review.

  10. How Should You Refactor • Refactor mercilessly • Refactor in small discrete steps • Test after each step • Refactor in pairs • Don’t mix with adding functionality or fixing a defect

  11. Automated Refactoring [The Smalltalk Refactoring Browser] completely changes the way you think about refactoring. All those niggling little “well, I should change this name but…” thoughts go away, because you just change the name because there is always a single menu item to just change the name.” --Kent Beck

  12. A Refactoring Tool for Tiger • The language is used in some compiler classes at UK • Implements the Extract Method refactoring • I practiced what I am preaching during its implementation.

  13. Refactoring Resources • Fowler, Martin. Refactoring: Improving the Design of Existing Code. 1999. • The Extreme Programming wiki – http://www.c2.com • JUnit – http://www.junit.org • This presentation – http://www.papermountain.org

More Related