Presentation is loading. Please wait.

Presentation is loading. Please wait.

Refactoring An Automated Tool for the Tiger Language Leslie A Hensley

Similar presentations


Presentation on theme: "Refactoring An Automated Tool for the Tiger Language Leslie A Hensley"— 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 http://www.c2.com JUnit – http://www.junit.orghttp://www.junit.org This presentation – http://www.papermountain.org http://www.papermountain.org


Download ppt "Refactoring An Automated Tool for the Tiger Language Leslie A Hensley"

Similar presentations


Ads by Google