130 likes | 414 Views
Refactoring Legacy Code. Andreas Enbohm @ enbohm 2013-09-11. About Me. What is Legacy Code ?. Legacy Code. Legacy Code is Simply Code Without Tests! (do you write legacy code ?). Refactoring. Sandro Mancuso http://craftedsw.blogspot.com. Refactoring Legacy Code.
E N D
Refactoring Legacy Code Andreas Enbohm @enbohm 2013-09-11
LegacyCode LegacyCode is SimplyCodeWithout Tests! (do youwritelegacycode?)
Refactoring Sandro Mancuso http://craftedsw.blogspot.com
RefactoringLegacyCode • Have a cleargoal- otherwise you couldend up just movingaroundcode and not makingthingsanybetter • Specify, don’tverify- aim is not to test code, but to produceartifacts that describesitsbehaviour (characterization tests)
Business ComponentWeWant to Change TweetService.java– a service responsible for finding tweets by a specificuser • Need to be logged in to seetweets by a particularuser • Need to be friends to seesomeoneelse’stweets
Tips • Use a codecoveragetool • Commitoften- enables you to commitimprovementsquickly- allows you to rollback if you make a mistake- remember, refactoringshould be done in small steps! • IdentifySeams- parts whereyoucanmodifybehaviourwithoutediting that place- useknowndependencybreakingtechniques to createseams • Stay in the ’green-zone’ as long as possible
Tips (cont) Start refactoring from deepest to shortestbranch if (…) { booleanparam… if (param) { if (getStuff()) { … } } } else { … } Start testing from shortest to deepestbranch
Q & A http://www.slideshare.net/enbohm @enbohm https://github.com/enbohm