SlideShare una empresa de Scribd logo
1 de 33
Descargar para leer sin conexión
Working 
Effec-vely 
with 
Legacy 
Code 
Lessons 
in 
Prac-ce
The 
Book 
by 
Michael 
C. 
Feathers 
published 
2004 
foreword 
by 
“Uncle 
Bob” 
Mar-n 
influenced 
by 
Mar-n 
Fowler’s 
Refactoring
What 
is 
Legacy 
Code? 
• “difficult 
to 
change 
code 
that 
I 
don’t 
understand” 
• “code 
wriNen 
a 
long 
-me 
ago” 
• “code 
that 
somebody 
else 
wrote”
Why 
do 
I 
need 
to 
understand 
the 
code? 
because 
SoTware 
is 
Never 
Done 
Refactor 
Add 
Feature 
Fix 
Bug 
Op4mize 
Structure 
Changes 
Changes 
Changes 
New 
Behavior 
Changes 
Exis-ng 
Behavior 
Changes 
Resource 
Usage 
Changes
What 
is 
Legacy 
Code? 
“Code 
Without 
Tests”
Two 
Methods 
of 
SoTware 
Development 
“Edit 
and 
Pray” 
vs. 
“Cover 
and 
Modify” 
which 
brings 
us 
to…
The 
Legacy 
Code 
Dilemma 
“When 
we 
change 
code, 
we 
should 
have 
tests 
in 
place.” 
“To 
put 
tests 
in 
place, 
we 
oTen 
have 
to 
change 
code.” 
(But 
why?)
Legacy 
Code 
Change 
Algorithm 
1. Iden-fy 
Change 
Point 
2. Find 
Test 
Point 
3. Break 
Dependency 
4. Write 
Tests 
5. Change 
and 
Refactor
Seams 
Exchangeable 
Behavior 
+ 
an 
Enabling 
Point. 
Seams 
let 
you 
subs7tute 
one 
behavior 
for 
another 
by 
edi-ng 
only 
at 
the 
enabling 
point. 
Seams 
let 
you 
introduce 
test 
collaborators.
Object 
Seams 
Most 
useful 
type 
of 
seam 
for 
OOP. 
Another 
way 
of 
talking 
about 
polymorphism. 
Code 
without 
seam 
Code 
with 
seam
In 
the 
Wild 
No 
Tests 
== 
No 
Up-­‐to-­‐Date 
Documenta-on 
instead 
of
In 
the 
Wild 
Duplicate 
Code
In 
the 
Wild 
Long, 
Procedural 
Methods 
def generate_pdf 
end
In 
the 
Wild 
Stateful 
Programming 
• Keeping 
Track 
of 
Flags 
• HTTP 
Session 
Abuse
In 
the 
Wild 
Curse 
of 
MVC 
• Fat 
Models, 
Fat 
Controllers 
• Overloaded 
Responsibili-es
So 
Many 
Problems 
Chapter 
6: 
“I 
Don’t 
Have 
Much 
Time 
and 
I 
Have 
to 
Change 
It” 
Chapter 
8: 
“It 
Takes 
Forever 
to 
Make 
a 
Change” 
Chapter 
10: 
“I 
Can’t 
Run 
This 
Method 
in 
a 
Test” 
Chapter 
16: 
“I 
Don’t 
Understand 
the 
Code 
Well 
Enough 
To 
Change 
It” 
Chapter 
17: 
“My 
Applica-on 
Has 
No 
Structure” 
Chapter 
19: 
“My 
Project 
Is 
Not 
Object 
Oriented. 
How 
Do 
I 
Make 
Safe 
Changes? 
Chapter 
20: 
“This 
Class 
Is 
Too 
Big 
and 
I 
Don’t 
Want 
It 
to 
Get 
Any 
Bigger”
This 
Class 
is 
Too 
Big 
Methods 
defined 
on 
Job:
Single 
Responsibility 
Principle 
“Every 
class 
should 
have 
a 
single 
responsibility: 
It 
should 
have 
a 
single 
purpose 
in 
the 
system, 
and 
there 
should 
be 
only 
one 
reason 
to 
change 
it.”
Seeing 
Responsibili-es 
Group 
Methods
Seeing 
Responsibili-es 
Effect 
Sketch: 
Show 
Internal 
Rela-onships
Seeing 
Responsibili-es 
Primary 
Responsibility 
“Job 
presents 
damper 
inspec-on 
data 
in 
report 
form.” 
“Job 
generates 
files 
of 
reports.” 
“Job 
deletes 
report 
files.” 
“Job 
produces 
graphs 
of 
damper 
inspec-on 
data.” 
“Job 
persists 
and 
retrieves 
representa-ons 
of 
jobs 
in 
a 
database.”
Iden-fy 
Change 
Point 
We 
want 
to 
refactor 
Job 
to 
extract 
Reporter. 
1. Iden-fy 
Change 
Point 
2. Find 
Test 
Point 
3. Break 
Dependency 
4. Write 
Tests 
5. Change 
and 
Refactor
Find 
Test 
Point 
Intercep-on 
Points 
Higher 
Level 
Tes-ng 
– don’t 
have 
to 
break 
dependencies 
– verifies 
that 
your 
feature 
actually 
works 
– slow, 
inconvenient 
– hard 
to 
automate 
– not 
tes-ng 
in 
isola-on 
Progressive 
Strategy 
1. Iden-fy 
Change 
Point 
2. Find 
Test 
Point 
3. Break 
Dependency 
4. Write 
Tests 
5. Change 
and 
Refactor
Break 
Dependencies 
Required 
for 
unit 
tes-ng. 
Less 
necessary 
for 
higher-­‐level 
tes-ng. 
We’re 
gonna 
skip 
it 
(but 
just 
this 
-me). 
1. Iden-fy 
Change 
Point 
2. Find 
Test 
Point 
3. Break 
Dependency 
4. Write 
Tests 
5. Change 
and 
Refactor
Write 
Tests 
“Tes-ng” 
in 
the 
Interac-ve 
Console: 
1. Iden-fy 
Change 
Point 
2. Find 
Test 
Point 
3. Break 
Dependency 
4. Write 
Tests 
5. Change 
and 
Refactor
Change 
and 
Refactor 
This 
was 
harder 
than 
it 
looks. 
1. Iden-fy 
Change 
Point 
2. Find 
Test 
Point 
3. Break 
Dependency 
4. Write 
Tests 
5. Change 
and 
Refactor
Refactored 
Code 
Five 
different 
extracted 
classes 
(plus 
two 
more)
Extract 
Class…Again
BeNer 
With 
Seam? 
We 
can 
add 
a 
seam 
by 
injec-ng 
the 
dependency 
on 
the 
reporter. 
This 
way, 
we 
can 
test 
in 
isola-on 
by 
passing 
in 
a 
FakeReporter. 
Unfortunately, 
this 
makes 
our 
produc-on 
code 
ugly:
Seams 
Everywhere
Legacy 
Code 
Ain’t 
So 
Bad 
• No 
writer’s 
block. 
• Learn 
as 
you 
go. 
• Easy 
scapegoat! 
• Unavoidable, 
so 
learn 
to 
love 
it.
Thanks 
J 
Working 
Effec7vely 
with 
Legacy 
Code 
Michael 
Feathers 
Amar 
Shah 
@amar47shah
because 
SoTware 
is 
Never 
Done 
Refactor 
to 
Remove 
Demeter 
Viola-on

Más contenido relacionado

La actualidad más candente

Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Dror Helper
 
VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)Rob Hale
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
 
Refactoring Legacy Code
Refactoring Legacy CodeRefactoring Legacy Code
Refactoring Legacy CodeAdam Culp
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveAlvaro Videla
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven DevelopmentTung Nguyen Thanh
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And RefactoringNaresh Jain
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best PracticesTomaš Maconko
 
Unit testing (workshop)
Unit testing (workshop)Unit testing (workshop)
Unit testing (workshop)Foyzul Karim
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing FundamentalsRichard Paul
 
Battle of The Mocking Frameworks
Battle of The Mocking FrameworksBattle of The Mocking Frameworks
Battle of The Mocking FrameworksDror Helper
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testingalessiopace
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard partsShaun Abram
 
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven developmentStephen Fuqua
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentConsulthinkspa
 
Roy Osherove TDD From Scratch
Roy Osherove TDD From ScratchRoy Osherove TDD From Scratch
Roy Osherove TDD From ScratchRoy Osherove
 
Refactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENGRefactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENGLuca Minudel
 

La actualidad más candente (20)

Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013
 
VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
Refactoring Legacy Code
Refactoring Legacy CodeRefactoring Legacy Code
Refactoring Legacy Code
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = Love
 
Unit Testing 101
Unit Testing 101Unit Testing 101
Unit Testing 101
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
 
TDD Basics with Angular.js and Jasmine
TDD Basics with Angular.js and JasmineTDD Basics with Angular.js and Jasmine
TDD Basics with Angular.js and Jasmine
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
 
Unit testing (workshop)
Unit testing (workshop)Unit testing (workshop)
Unit testing (workshop)
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
 
Battle of The Mocking Frameworks
Battle of The Mocking FrameworksBattle of The Mocking Frameworks
Battle of The Mocking Frameworks
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard parts
 
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Roy Osherove TDD From Scratch
Roy Osherove TDD From ScratchRoy Osherove TDD From Scratch
Roy Osherove TDD From Scratch
 
Refactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENGRefactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENG
 

Destacado

Destacado (6)

NewWork in der Praxis
NewWork in der PraxisNewWork in der Praxis
NewWork in der Praxis
 
Integration Test Hell
Integration Test HellIntegration Test Hell
Integration Test Hell
 
Mockist vs Classicists TDD
Mockist vs Classicists TDDMockist vs Classicists TDD
Mockist vs Classicists TDD
 
Quo vadis DevOps
Quo vadis DevOpsQuo vadis DevOps
Quo vadis DevOps
 
Von Kutschern, Managern und Systemadministratoren
Von Kutschern, Managern und SystemadministratorenVon Kutschern, Managern und Systemadministratoren
Von Kutschern, Managern und Systemadministratoren
 
DevOps jenseits der Tools
DevOps jenseits der ToolsDevOps jenseits der Tools
DevOps jenseits der Tools
 

Similar a Working Effectively with Legacy Code: Lessons in Practice

Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean CodingMetin Ogurlu
 
Refactoring workshop
Refactoring workshop Refactoring workshop
Refactoring workshop Itzik Saban
 
Clean code quotes - Citações e provocações
Clean code quotes - Citações e provocaçõesClean code quotes - Citações e provocações
Clean code quotes - Citações e provocaçõesAndré de Fontana Ignacio
 
MongoDB World 2018: Tutorial - MongoDB Meets Chaos Monkey
MongoDB World 2018: Tutorial - MongoDB Meets Chaos MonkeyMongoDB World 2018: Tutorial - MongoDB Meets Chaos Monkey
MongoDB World 2018: Tutorial - MongoDB Meets Chaos MonkeyMongoDB
 
Bye Bye Cowboy Coder Days! (Legacy Code & TDD)
Bye Bye Cowboy Coder Days! (Legacy Code & TDD)Bye Bye Cowboy Coder Days! (Legacy Code & TDD)
Bye Bye Cowboy Coder Days! (Legacy Code & TDD)Kaunas Java User Group
 
Test Driven Development - Workshop
Test Driven Development - WorkshopTest Driven Development - Workshop
Test Driven Development - WorkshopAnjana Somathilake
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing SoftwareSteven Smith
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Red Gate Software
 
Commonly used design patterns
Commonly used design patternsCommonly used design patterns
Commonly used design patternsMojammel Haque
 
Mock Objects, Design and Dependency Inversion Principle
Mock Objects, Design and Dependency Inversion PrincipleMock Objects, Design and Dependency Inversion Principle
Mock Objects, Design and Dependency Inversion PrincipleP Heinonen
 
Refactoring Legacy Code - true story
Refactoring Legacy Code - true storyRefactoring Legacy Code - true story
Refactoring Legacy Code - true storyAki Salmi
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...AgileNetwork
 
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Mozaic Works
 
Making a Mock by Kelsey Shannahan
Making a Mock by Kelsey ShannahanMaking a Mock by Kelsey Shannahan
Making a Mock by Kelsey ShannahanQA or the Highway
 
2020-Feb: Testing: Cables and Chains
2020-Feb: Testing: Cables and Chains2020-Feb: Testing: Cables and Chains
2020-Feb: Testing: Cables and ChainsMark Windholtz
 
Test driven development
Test driven developmentTest driven development
Test driven developmentnamkha87
 

Similar a Working Effectively with Legacy Code: Lessons in Practice (20)

Unit Testing in Swift
Unit Testing in SwiftUnit Testing in Swift
Unit Testing in Swift
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
 
Refactoring workshop
Refactoring workshop Refactoring workshop
Refactoring workshop
 
Clean code quotes - Citações e provocações
Clean code quotes - Citações e provocaçõesClean code quotes - Citações e provocações
Clean code quotes - Citações e provocações
 
MongoDB World 2018: Tutorial - MongoDB Meets Chaos Monkey
MongoDB World 2018: Tutorial - MongoDB Meets Chaos MonkeyMongoDB World 2018: Tutorial - MongoDB Meets Chaos Monkey
MongoDB World 2018: Tutorial - MongoDB Meets Chaos Monkey
 
Bye Bye Cowboy Coder Days! (Legacy Code & TDD)
Bye Bye Cowboy Coder Days! (Legacy Code & TDD)Bye Bye Cowboy Coder Days! (Legacy Code & TDD)
Bye Bye Cowboy Coder Days! (Legacy Code & TDD)
 
Clean code
Clean codeClean code
Clean code
 
Declarative Network Configuration
Declarative Network Configuration Declarative Network Configuration
Declarative Network Configuration
 
Test Driven Development - Workshop
Test Driven Development - WorkshopTest Driven Development - Workshop
Test Driven Development - Workshop
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014
 
Commonly used design patterns
Commonly used design patternsCommonly used design patterns
Commonly used design patterns
 
Mock Objects, Design and Dependency Inversion Principle
Mock Objects, Design and Dependency Inversion PrincipleMock Objects, Design and Dependency Inversion Principle
Mock Objects, Design and Dependency Inversion Principle
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Refactoring Legacy Code - true story
Refactoring Legacy Code - true storyRefactoring Legacy Code - true story
Refactoring Legacy Code - true story
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
 
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
 
Making a Mock by Kelsey Shannahan
Making a Mock by Kelsey ShannahanMaking a Mock by Kelsey Shannahan
Making a Mock by Kelsey Shannahan
 
2020-Feb: Testing: Cables and Chains
2020-Feb: Testing: Cables and Chains2020-Feb: Testing: Cables and Chains
2020-Feb: Testing: Cables and Chains
 
Test driven development
Test driven developmentTest driven development
Test driven development
 

Último

%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 

Último (20)

%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 

Working Effectively with Legacy Code: Lessons in Practice

  • 1. Working Effec-vely with Legacy Code Lessons in Prac-ce
  • 2. The Book by Michael C. Feathers published 2004 foreword by “Uncle Bob” Mar-n influenced by Mar-n Fowler’s Refactoring
  • 3. What is Legacy Code? • “difficult to change code that I don’t understand” • “code wriNen a long -me ago” • “code that somebody else wrote”
  • 4. Why do I need to understand the code? because SoTware is Never Done Refactor Add Feature Fix Bug Op4mize Structure Changes Changes Changes New Behavior Changes Exis-ng Behavior Changes Resource Usage Changes
  • 5. What is Legacy Code? “Code Without Tests”
  • 6. Two Methods of SoTware Development “Edit and Pray” vs. “Cover and Modify” which brings us to…
  • 7. The Legacy Code Dilemma “When we change code, we should have tests in place.” “To put tests in place, we oTen have to change code.” (But why?)
  • 8. Legacy Code Change Algorithm 1. Iden-fy Change Point 2. Find Test Point 3. Break Dependency 4. Write Tests 5. Change and Refactor
  • 9. Seams Exchangeable Behavior + an Enabling Point. Seams let you subs7tute one behavior for another by edi-ng only at the enabling point. Seams let you introduce test collaborators.
  • 10. Object Seams Most useful type of seam for OOP. Another way of talking about polymorphism. Code without seam Code with seam
  • 11. In the Wild No Tests == No Up-­‐to-­‐Date Documenta-on instead of
  • 12. In the Wild Duplicate Code
  • 13. In the Wild Long, Procedural Methods def generate_pdf end
  • 14. In the Wild Stateful Programming • Keeping Track of Flags • HTTP Session Abuse
  • 15. In the Wild Curse of MVC • Fat Models, Fat Controllers • Overloaded Responsibili-es
  • 16. So Many Problems Chapter 6: “I Don’t Have Much Time and I Have to Change It” Chapter 8: “It Takes Forever to Make a Change” Chapter 10: “I Can’t Run This Method in a Test” Chapter 16: “I Don’t Understand the Code Well Enough To Change It” Chapter 17: “My Applica-on Has No Structure” Chapter 19: “My Project Is Not Object Oriented. How Do I Make Safe Changes? Chapter 20: “This Class Is Too Big and I Don’t Want It to Get Any Bigger”
  • 17. This Class is Too Big Methods defined on Job:
  • 18. Single Responsibility Principle “Every class should have a single responsibility: It should have a single purpose in the system, and there should be only one reason to change it.”
  • 20. Seeing Responsibili-es Effect Sketch: Show Internal Rela-onships
  • 21. Seeing Responsibili-es Primary Responsibility “Job presents damper inspec-on data in report form.” “Job generates files of reports.” “Job deletes report files.” “Job produces graphs of damper inspec-on data.” “Job persists and retrieves representa-ons of jobs in a database.”
  • 22. Iden-fy Change Point We want to refactor Job to extract Reporter. 1. Iden-fy Change Point 2. Find Test Point 3. Break Dependency 4. Write Tests 5. Change and Refactor
  • 23. Find Test Point Intercep-on Points Higher Level Tes-ng – don’t have to break dependencies – verifies that your feature actually works – slow, inconvenient – hard to automate – not tes-ng in isola-on Progressive Strategy 1. Iden-fy Change Point 2. Find Test Point 3. Break Dependency 4. Write Tests 5. Change and Refactor
  • 24. Break Dependencies Required for unit tes-ng. Less necessary for higher-­‐level tes-ng. We’re gonna skip it (but just this -me). 1. Iden-fy Change Point 2. Find Test Point 3. Break Dependency 4. Write Tests 5. Change and Refactor
  • 25. Write Tests “Tes-ng” in the Interac-ve Console: 1. Iden-fy Change Point 2. Find Test Point 3. Break Dependency 4. Write Tests 5. Change and Refactor
  • 26. Change and Refactor This was harder than it looks. 1. Iden-fy Change Point 2. Find Test Point 3. Break Dependency 4. Write Tests 5. Change and Refactor
  • 27. Refactored Code Five different extracted classes (plus two more)
  • 29. BeNer With Seam? We can add a seam by injec-ng the dependency on the reporter. This way, we can test in isola-on by passing in a FakeReporter. Unfortunately, this makes our produc-on code ugly:
  • 31. Legacy Code Ain’t So Bad • No writer’s block. • Learn as you go. • Easy scapegoat! • Unavoidable, so learn to love it.
  • 32. Thanks J Working Effec7vely with Legacy Code Michael Feathers Amar Shah @amar47shah
  • 33. because SoTware is Never Done Refactor to Remove Demeter Viola-on