SlideShare a Scribd company logo
Refactoring Legacy Code 
Pablo Machado 
machadoum@gmail.com
Legacy Code? 
Code written using old technology? 
Code written by somebody who doesn't work 
for the company anymore? 
A code very fragile or complicated?
Legacy Code 
➔ Hard to understand and maintain 
➔ Intimidating to be changed
Legacy Code? 
“To me, legacy code is simply code without tests.” 
Michael Feathers
Legacy Code? 
“If you wrote a new feature today, which took you a lot of mental 
energy and time, and tomorrow you'll be afraid to change it …”
Refactoring?
Why Refactor? 
➔ To understand the code 
➔ To improve the health of code-base 
➔ To be confident 
➔ To optimize for readability
Why Refactor? 
➔ To understand the code 
➔ To improve the health of code-base 
➔ To be confident 
➔ To optimize for readability
Refactoring legacy code
The Fear Factor
Unit Test 
Characterization tests
Refactor Dilemma 
When we refactor, we should have tests. 
To test we often have to refactor.
Legacy Code Change 
Identify Change Points 
Identify Test Points 
Break Dependecies 
Write Test 
Refactor
Working Effectively With 
Legacy Code
Working Effectively With 
Legacy Code 
Baby Steps
Working Effectively With 
Legacy Code 
Invest only where necessary
Working Effectively With 
Legacy Code 
Know how to use the tools
Refactoring legacy code
Breaking Dependencies
External Dependencies 
Production Code
External Dependencies 
Production Code 
Test Code
External Dependencies 
Production Code 
Test Code
Internal/Hidden 
dependencies 
Production Code Refactor To Test
Production Code Test Code 
Test Code 
Internal/Hidden 
dependencies
Refactor Technique
Sprout Method 
When? 
Add a feature as completely new code in a untestable method. 
How? 
Identify the inputs and outputs of the new method 
Create a call for the new method 
Develop the new method with TDD
Sprout Method 
Advantages 
Test new code 
Separeta new cold from the old 
Disadvantages 
Dont test old code 
Dont make the code better
Wrap Class 
When? 
Add a feature as completely new code in complex class. 
How? 
Create a class and extend the old class 
Override the old method and make a call 
Develop the new method with TDD
Sprout Method 
Advantages 
Test new code 
Separeta new cold from the old 
Disadvantages 
Dont test old code 
Dont make the code better
Referências 
http://refactoring.com/
Refactoring legacy code

More Related Content

PPS
Test Driven Development by Sameer Arora
PPTX
Helping Programmers Write Better Tests
PPTX
XP Injection
PPTX
Code review
PPTX
How to be proud when you are done
PDF
Intro TDD Portuguese developers meetup London 16/04/2014
ODP
Tdd in php a brief example
PPTX
Code Review
Test Driven Development by Sameer Arora
Helping Programmers Write Better Tests
XP Injection
Code review
How to be proud when you are done
Intro TDD Portuguese developers meetup London 16/04/2014
Tdd in php a brief example
Code Review

What's hot (20)

PDF
Software craftmanship coaching
PPT
Test Driven Development - Overview and Adoption
PDF
How to successfully grow a code review culture
PPTX
Finding a good development partner
PDF
Introduction to test_driven_development
PDF
Tdd2018 state of the software quality in Germany
PDF
Boquet manager
PDF
Code Review for iOS
PPTX
Code Review Best Practices
ODP
TDD in PHP - Memphis PHP 2011-08-25
PPTX
Journey of atdd
PPTX
Agile testingandautomation
PDF
Agile Testing 20021015
PDF
Test Driven Development Powered by LEGO
PDF
Code Review: How and When
ODP
A Brief Introduction to Zend_Form
PDF
To test or not to test? this is the prblem
PDF
Job manager 2020 in Angular
ODP
Zero to Zend Framework in 10 minutes
PPTX
Code review at large scale
Software craftmanship coaching
Test Driven Development - Overview and Adoption
How to successfully grow a code review culture
Finding a good development partner
Introduction to test_driven_development
Tdd2018 state of the software quality in Germany
Boquet manager
Code Review for iOS
Code Review Best Practices
TDD in PHP - Memphis PHP 2011-08-25
Journey of atdd
Agile testingandautomation
Agile Testing 20021015
Test Driven Development Powered by LEGO
Code Review: How and When
A Brief Introduction to Zend_Form
To test or not to test? this is the prblem
Job manager 2020 in Angular
Zero to Zend Framework in 10 minutes
Code review at large scale
Ad

Similar to Refactoring legacy code (20)

PPTX
Agile Australia 2016 - Rescuing Legacy Software from Impending Doom
PPTX
Taming scary production code that nobody wants to touch
PPTX
Working Effectively with Legacy Code
PPTX
Refactoring workshop
PDF
The Power Of Refactoring (php|tek 09)
PDF
Software Craftsmanship
PDF
Workshop fight legacy code write unit test
PDF
[XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015]
PDF
The Power Of Refactoring (4developers Krakow)
PDF
Big code refactoring with agility
PDF
Refactoring 2TheMax (con ReSharper)
PPTX
Refactoring & Testing software.
PDF
Working With Legacy Code
PPTX
Refactoring, 2nd Edition
PDF
The Power Of Refactoring (PHPCon Italia)
PPTX
Working Effectively With Legacy Code
PPTX
Working with Legacy Code
PPTX
Code refactoring
PPTX
Test Drive Dirven Driver HAHAahhaha.pptx
PPTX
Refactor your code: when, why and how?
Agile Australia 2016 - Rescuing Legacy Software from Impending Doom
Taming scary production code that nobody wants to touch
Working Effectively with Legacy Code
Refactoring workshop
The Power Of Refactoring (php|tek 09)
Software Craftsmanship
Workshop fight legacy code write unit test
[XPday.vn] Legacy code workshop (at) [XP Day Vietnam 2015]
The Power Of Refactoring (4developers Krakow)
Big code refactoring with agility
Refactoring 2TheMax (con ReSharper)
Refactoring & Testing software.
Working With Legacy Code
Refactoring, 2nd Edition
The Power Of Refactoring (PHPCon Italia)
Working Effectively With Legacy Code
Working with Legacy Code
Code refactoring
Test Drive Dirven Driver HAHAahhaha.pptx
Refactor your code: when, why and how?
Ad

Recently uploaded (20)

PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Transform Your Business with a Software ERP System
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
System and Network Administraation Chapter 3
PDF
Nekopoi APK 2025 free lastest update
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
history of c programming in notes for students .pptx
PPTX
Introduction to Artificial Intelligence
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Transform Your Business with a Software ERP System
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Design an Analysis of Algorithms I-SECS-1021-03
Which alternative to Crystal Reports is best for small or large businesses.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
System and Network Administraation Chapter 3
Nekopoi APK 2025 free lastest update
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
How to Choose the Right IT Partner for Your Business in Malaysia
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
history of c programming in notes for students .pptx
Introduction to Artificial Intelligence
VVF-Customer-Presentation2025-Ver1.9.pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Odoo POS Development Services by CandidRoot Solutions
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus

Refactoring legacy code