SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Working Effectively with
  Legacy Code
                     Roberto Hernandez-Pou
                     Managing Consultant
                     Excella Consulting
                     @hernandezrobert
                     http://www.overridethis.com



Excella Consulting – http://www.excella.com
Legacy Code: Characteristics

•    Poor Architecture
•    Non-Uniform coding styles
•    Poor or Non-Existing Documentation
•    Mythical “Oral” Documentation
•    No Tests (or Minimal Test Coverage)
• Extremely Valuable!
       – Only Successful code becomes Legacy Code.




Excella Consulting – http://www.excella.com                                  #DCAEC12   @HernandezRobert
* Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
Agenda

•    How does code become Legacy Code?
•    Reasons to work with Legacy Code
•    What are my options?
•    How do we approach the work?
       – Edit and Pray „or‟ Cover and Modify
•    The Legacy Code Change Algorithm
•    Sensing and Separation
•    Fake Collaborators
•    Seams
•    Tools
•    TDD for Legacy Code


Excella Consulting – http://www.excella.com                                  #DCAEC12   @HernandezRobert
* Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
How does code become Legacy Code?

• New Features or New Requirements
       – Developers usually turn to shortcuts and hacks to make deadlines
         and deliver on time to market.


• Software Team Turnover or Large Development Teams
       – Multiple styles of coding.
       – Lack of vision.
       – Code duplication.


• Poor Team Communication.



Excella Consulting – http://www.excella.com                                  #DCAEC12   @HernandezRobert
* Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
Reasons to “Work with Legacy Code”

• Four reasons to change software:
       –   Adding a feature
       –   Fixing a bug
       –   Refactoring
       –   Optimizing resource usage
                               Adding a Feature         Fixing a Bug         Refactoring     Optimizing
                                                                                           resource usage
    Structure                       Changes               Changes                Changes

    New Functionality               Changes

    Functionality                                         Changes

    Resource Usage                                                                            Changes


Excella Consulting – http://www.excella.com                                  #DCAEC12       @HernandezRobert
* Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
As a Developer what are my options?

• Look for a new Job?
• Start from scratch.
       – Big bang approach!
• Have somebody else do the job:
       – Members of the original development team
       – Consultants ($$$)

• Deal with it!


Excella Consulting – http://www.excella.com                                  #DCAEC12   @HernandezRobert
* Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
How do we approach the work?

• Working with Feedback
       – Edit and pray
          (Industry standard)

       – Cover and modify




Excella Consulting – http://www.excella.com                                  #DCAEC12   @HernandezRobert
* Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
Edit and Pray

•   Carefully plan the changes
•   Make sure you understand the code
•   Start making changes
•   Poke around to see if you broke anything
•   Deploy to production environment
•   Wait for feedback from customers
Cover and Modify

• Build a safety net (Covering = Testing)
• Unit Testing
• Higher level testing


                                   The Legacy Code Dilemma
                      When we change code, we should have tests in place.
                         To put tests in place we need to change code




Excella Consulting – http://www.excella.com                                  #DCAEC12   @HernandezRobert
* Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
Cover and Modify

• Introduce Unit Tests

• Unit Tests are:
       –   Fast
       –   Localise Problems
       –   Do not talk to a database
       –   Do not communicate over the network
       –   Do not communicate with local resources
       –   Do not need config changes




Excella Consulting – http://www.excella.com                                  #DCAEC12   @HernandezRobert
* Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
The Legacy Code Change Algorithm

    Identify change points
    Find test points
    Break dependencies
    Write tests
    Make changes and refactor




Excella Consulting – http://www.excella.com                                  #DCAEC12   @HernandezRobert
* Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
Sensing & Separation


• Sensing: we break dependencies to sense when we can't access
  values our code computes

• Separation: we break dependencies to separate when we can't
  even get a piece of code into a test harness to run




Excella Consulting – http://www.excella.com                                  #DCAEC12   @HernandezRobert
* Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
Fake Collaborators

• Object that impersonates some collaborator of your class when its
  being tested.
       – Demo: Echo Console




Excella Consulting – http://www.excella.com                                  #DCAEC12   @HernandezRobert
* Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
The Seam Model

• Seam: a place where you can alter behavior of your program
  without editing in that place.
• Enabling Point: Every seam has an enabling point, a place where
  you can make the decision to use one behavior or another.

• Looking for existing seams in legacy code allow us to break
  dependencies (for sensing or separation) without refactoring.

• Demo: Echo Console
• Demo: Fake Data Reader


Excella Consulting – http://www.excella.com                                  #DCAEC12   @HernandezRobert
* Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
Tools




Excella Consulting – http://www.excella.com                                  #DCAEC12   @HernandezRobert
* Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
Test Driven Development

• Test-Driven Development (TDD)

       1. Write a failing test
       2. Get it to compile
       3. Make it pass
       4. Remove duplication
       5. Repeat


• Programming by difference




Excella Consulting – http://www.excella.com                                  #DCAEC12   @HernandezRobert
* Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
Test Driven Development

• Test-Driven Development (TDD) for legacy

       0. Get the class you want to change under test
       1. Write a failing test
       2. Get it to compile
       3. Make it pass (try not to change existing code)
       4. Remove duplication
       5. Repeat


• Programming by difference



Excella Consulting – http://www.excella.com                                  #DCAEC12   @HernandezRobert
* Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
Conclusions

• No “silver bullet” here, it's hard work but not impossible
• Overwhelming at first but things will get better as the number of
  tests increase
• Be pragmatic!
Resources


           “Working Effectively with Legacy Code” by
   1.
           Michael Feathers

   2.      http://www.objectmentor.com

   3.      http://www.overridethis.com

           http://bitbucket.org/rhp_74/overridethis.legacycode
   4.
           sample

Excella Consulting – http://www.excella.com
Thank You!


   1.      Blog: http://www.overridethis.com

   2.      Email: roberto.hernandez@excella.com

   3.      @hernandezrobert

   4.


Excella Consulting – http://www.excella.com

Weitere ähnliche Inhalte

Andere mochten auch

чужинова нв, шляхтина он
чужинова нв, шляхтина ончужинова нв, шляхтина он
чужинова нв, шляхтина он
chuginova
 
Destiny’s christmas speech
Destiny’s christmas speechDestiny’s christmas speech
Destiny’s christmas speech
slrussell1
 
Scatol8 UUDD livello A_2
Scatol8 UUDD livello A_2Scatol8 UUDD livello A_2
Scatol8 UUDD livello A_2
Scatol8
 
عرض الدرعية
عرض الدرعيةعرض الدرعية
عرض الدرعية
MHSEN_46
 
Coffee Shop Security Group Tool
Coffee Shop Security Group ToolCoffee Shop Security Group Tool
Coffee Shop Security Group Tool
joehack3r
 
Discover the power to be truly
Discover the power to be trulyDiscover the power to be truly
Discover the power to be truly
treasure4me
 
Presentatie VOV- retentie
Presentatie VOV- retentiePresentatie VOV- retentie
Presentatie VOV- retentie
Aerts_Sabine
 

Andere mochten auch (20)

чужинова нв, шляхтина он
чужинова нв, шляхтина ончужинова нв, шляхтина он
чужинова нв, шляхтина он
 
Destiny’s christmas speech
Destiny’s christmas speechDestiny’s christmas speech
Destiny’s christmas speech
 
Scatol8 UUDD livello A_2
Scatol8 UUDD livello A_2Scatol8 UUDD livello A_2
Scatol8 UUDD livello A_2
 
自己的遊戲自己寫 - 立志中學 2014/12/1 遊戲設計分享簡報
自己的遊戲自己寫 - 立志中學 2014/12/1 遊戲設計分享簡報自己的遊戲自己寫 - 立志中學 2014/12/1 遊戲設計分享簡報
自己的遊戲自己寫 - 立志中學 2014/12/1 遊戲設計分享簡報
 
svt
svtsvt
svt
 
عرض الدرعية
عرض الدرعيةعرض الدرعية
عرض الدرعية
 
math
mathmath
math
 
Tmđt
TmđtTmđt
Tmđt
 
La crudelta
La crudeltaLa crudelta
La crudelta
 
svt2
svt2svt2
svt2
 
Coffee Shop Security Group Tool
Coffee Shop Security Group ToolCoffee Shop Security Group Tool
Coffee Shop Security Group Tool
 
[CLP] IT industry Day 2 - 4
[CLP] IT industry  Day 2 - 4[CLP] IT industry  Day 2 - 4
[CLP] IT industry Day 2 - 4
 
Discover the power to be truly
Discover the power to be trulyDiscover the power to be truly
Discover the power to be truly
 
Presentatie VOV- retentie
Presentatie VOV- retentiePresentatie VOV- retentie
Presentatie VOV- retentie
 
Feliz dia del maestro.pptx rr
Feliz dia del maestro.pptx rrFeliz dia del maestro.pptx rr
Feliz dia del maestro.pptx rr
 
Villast longani
Villast longaniVillast longani
Villast longani
 
Larry Logan Live Webinar: Winning Customer Loyalty Through Digitally Empowere...
Larry Logan Live Webinar: Winning Customer Loyalty Through Digitally Empowere...Larry Logan Live Webinar: Winning Customer Loyalty Through Digitally Empowere...
Larry Logan Live Webinar: Winning Customer Loyalty Through Digitally Empowere...
 
Employment Testing in HRM.
Employment Testing in HRM.Employment Testing in HRM.
Employment Testing in HRM.
 
Teorías de la Psicología Educativa
 Teorías de la Psicología Educativa Teorías de la Psicología Educativa
Teorías de la Psicología Educativa
 
Trabajo grupal
Trabajo grupalTrabajo grupal
Trabajo grupal
 

Ähnlich wie Working with Legacy Code

How to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle coreHow to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle core
Dan Poltawski
 
Puppet Camp Austin 2015: Getting Started with Puppet
Puppet Camp Austin 2015: Getting Started with PuppetPuppet Camp Austin 2015: Getting Started with Puppet
Puppet Camp Austin 2015: Getting Started with Puppet
Puppet
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
Mike Harris
 

Ähnlich wie Working with Legacy Code (20)

Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
 
Create Your Own Starter Files
Create Your Own Starter FilesCreate Your Own Starter Files
Create Your Own Starter Files
 
Agile, Automated, Aware: How to Model for Success
Agile, Automated, Aware: How to Model for SuccessAgile, Automated, Aware: How to Model for Success
Agile, Automated, Aware: How to Model for Success
 
Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
 
Top 10 Reasons to Switch to ER/Studio
Top 10 Reasons to Switch to ER/Studio Top 10 Reasons to Switch to ER/Studio
Top 10 Reasons to Switch to ER/Studio
 
Alex Theedom Java ee revisits design patterns
Alex Theedom	Java ee revisits design patternsAlex Theedom	Java ee revisits design patterns
Alex Theedom Java ee revisits design patterns
 
SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"
 
14 Habits of Great SQL Developers
14 Habits of Great SQL Developers14 Habits of Great SQL Developers
14 Habits of Great SQL Developers
 
Data Modeling for NoSQL
Data Modeling for NoSQLData Modeling for NoSQL
Data Modeling for NoSQL
 
How to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle coreHow to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle core
 
TDD and the Legacy Code Black Hole
TDD and the Legacy Code Black HoleTDD and the Legacy Code Black Hole
TDD and the Legacy Code Black Hole
 
14 Habits of Great SQL Developers
14 Habits of Great SQL Developers14 Habits of Great SQL Developers
14 Habits of Great SQL Developers
 
Intelligent content and Flare
Intelligent content and Flare Intelligent content and Flare
Intelligent content and Flare
 
Art of refactoring - Code Smells and Microservices Antipatterns
Art of refactoring - Code Smells and Microservices AntipatternsArt of refactoring - Code Smells and Microservices Antipatterns
Art of refactoring - Code Smells and Microservices Antipatterns
 
Puppet Camp Austin 2015: Getting Started with Puppet
Puppet Camp Austin 2015: Getting Started with PuppetPuppet Camp Austin 2015: Getting Started with Puppet
Puppet Camp Austin 2015: Getting Started with Puppet
 
SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016
 
Building a Collaborative Data Architecture
Building a Collaborative Data ArchitectureBuilding a Collaborative Data Architecture
Building a Collaborative Data Architecture
 
4 roles on the it project team
4 roles on the it project team4 roles on the it project team
4 roles on the it project team
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
 

Mehr von DC Agile Engineering Conference (6)

Unindented Code Cannot Possibly Work
Unindented Code Cannot Possibly WorkUnindented Code Cannot Possibly Work
Unindented Code Cannot Possibly Work
 
Lead by Example
Lead by ExampleLead by Example
Lead by Example
 
Continuous Integration: Toolbox, Blueprint, Master Craft
Continuous Integration: Toolbox, Blueprint, Master CraftContinuous Integration: Toolbox, Blueprint, Master Craft
Continuous Integration: Toolbox, Blueprint, Master Craft
 
Continuous Delivery Applied
Continuous Delivery AppliedContinuous Delivery Applied
Continuous Delivery Applied
 
Agile Engineering and Software Craftsmanship
Agile Engineering and Software CraftsmanshipAgile Engineering and Software Craftsmanship
Agile Engineering and Software Craftsmanship
 
Improving Design through TDD
Improving Design through TDDImproving Design through TDD
Improving Design through TDD
 

Kürzlich hochgeladen

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Kürzlich hochgeladen (20)

Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdf
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Buy Epson EcoTank L3210 Colour Printer Online.pdf
Buy Epson EcoTank L3210 Colour Printer Online.pdfBuy Epson EcoTank L3210 Colour Printer Online.pdf
Buy Epson EcoTank L3210 Colour Printer Online.pdf
 

Working with Legacy Code

  • 1. Working Effectively with Legacy Code Roberto Hernandez-Pou Managing Consultant Excella Consulting @hernandezrobert http://www.overridethis.com Excella Consulting – http://www.excella.com
  • 2. Legacy Code: Characteristics • Poor Architecture • Non-Uniform coding styles • Poor or Non-Existing Documentation • Mythical “Oral” Documentation • No Tests (or Minimal Test Coverage) • Extremely Valuable! – Only Successful code becomes Legacy Code. Excella Consulting – http://www.excella.com #DCAEC12 @HernandezRobert * Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
  • 3. Agenda • How does code become Legacy Code? • Reasons to work with Legacy Code • What are my options? • How do we approach the work? – Edit and Pray „or‟ Cover and Modify • The Legacy Code Change Algorithm • Sensing and Separation • Fake Collaborators • Seams • Tools • TDD for Legacy Code Excella Consulting – http://www.excella.com #DCAEC12 @HernandezRobert * Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
  • 4. How does code become Legacy Code? • New Features or New Requirements – Developers usually turn to shortcuts and hacks to make deadlines and deliver on time to market. • Software Team Turnover or Large Development Teams – Multiple styles of coding. – Lack of vision. – Code duplication. • Poor Team Communication. Excella Consulting – http://www.excella.com #DCAEC12 @HernandezRobert * Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
  • 5. Reasons to “Work with Legacy Code” • Four reasons to change software: – Adding a feature – Fixing a bug – Refactoring – Optimizing resource usage Adding a Feature Fixing a Bug Refactoring Optimizing resource usage Structure Changes Changes Changes New Functionality Changes Functionality Changes Resource Usage Changes Excella Consulting – http://www.excella.com #DCAEC12 @HernandezRobert * Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
  • 6. As a Developer what are my options? • Look for a new Job? • Start from scratch. – Big bang approach! • Have somebody else do the job: – Members of the original development team – Consultants ($$$) • Deal with it! Excella Consulting – http://www.excella.com #DCAEC12 @HernandezRobert * Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
  • 7. How do we approach the work? • Working with Feedback – Edit and pray (Industry standard) – Cover and modify Excella Consulting – http://www.excella.com #DCAEC12 @HernandezRobert * Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
  • 8. Edit and Pray • Carefully plan the changes • Make sure you understand the code • Start making changes • Poke around to see if you broke anything • Deploy to production environment • Wait for feedback from customers
  • 9. Cover and Modify • Build a safety net (Covering = Testing) • Unit Testing • Higher level testing The Legacy Code Dilemma When we change code, we should have tests in place. To put tests in place we need to change code Excella Consulting – http://www.excella.com #DCAEC12 @HernandezRobert * Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
  • 10. Cover and Modify • Introduce Unit Tests • Unit Tests are: – Fast – Localise Problems – Do not talk to a database – Do not communicate over the network – Do not communicate with local resources – Do not need config changes Excella Consulting – http://www.excella.com #DCAEC12 @HernandezRobert * Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
  • 11. The Legacy Code Change Algorithm  Identify change points  Find test points  Break dependencies  Write tests  Make changes and refactor Excella Consulting – http://www.excella.com #DCAEC12 @HernandezRobert * Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
  • 12. Sensing & Separation • Sensing: we break dependencies to sense when we can't access values our code computes • Separation: we break dependencies to separate when we can't even get a piece of code into a test harness to run Excella Consulting – http://www.excella.com #DCAEC12 @HernandezRobert * Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
  • 13. Fake Collaborators • Object that impersonates some collaborator of your class when its being tested. – Demo: Echo Console Excella Consulting – http://www.excella.com #DCAEC12 @HernandezRobert * Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
  • 14. The Seam Model • Seam: a place where you can alter behavior of your program without editing in that place. • Enabling Point: Every seam has an enabling point, a place where you can make the decision to use one behavior or another. • Looking for existing seams in legacy code allow us to break dependencies (for sensing or separation) without refactoring. • Demo: Echo Console • Demo: Fake Data Reader Excella Consulting – http://www.excella.com #DCAEC12 @HernandezRobert * Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
  • 15. Tools Excella Consulting – http://www.excella.com #DCAEC12 @HernandezRobert * Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
  • 16. Test Driven Development • Test-Driven Development (TDD) 1. Write a failing test 2. Get it to compile 3. Make it pass 4. Remove duplication 5. Repeat • Programming by difference Excella Consulting – http://www.excella.com #DCAEC12 @HernandezRobert * Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
  • 17. Test Driven Development • Test-Driven Development (TDD) for legacy 0. Get the class you want to change under test 1. Write a failing test 2. Get it to compile 3. Make it pass (try not to change existing code) 4. Remove duplication 5. Repeat • Programming by difference Excella Consulting – http://www.excella.com #DCAEC12 @HernandezRobert * Based on the Book “Working Effectively with Legacy Code” by Michael Feathers
  • 18. Conclusions • No “silver bullet” here, it's hard work but not impossible • Overwhelming at first but things will get better as the number of tests increase • Be pragmatic!
  • 19. Resources “Working Effectively with Legacy Code” by 1. Michael Feathers 2. http://www.objectmentor.com 3. http://www.overridethis.com http://bitbucket.org/rhp_74/overridethis.legacycode 4. sample Excella Consulting – http://www.excella.com
  • 20. Thank You! 1. Blog: http://www.overridethis.com 2. Email: roberto.hernandez@excella.com 3. @hernandezrobert 4. Excella Consulting – http://www.excella.com