SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Model driven software engineering in practice book - chapter 7 - Developing y...
Model driven software engineering in practice book - chapter 7 - Developing y...Model driven software engineering in practice book - chapter 7 - Developing y...
Model driven software engineering in practice book - chapter 7 - Developing y...
Marco Brambilla
 

Mais procurados (20)

Clean code
Clean codeClean code
Clean code
 
Refactoring
RefactoringRefactoring
Refactoring
 
Testing with JUnit 5 and Spring
Testing with JUnit 5 and SpringTesting with JUnit 5 and Spring
Testing with JUnit 5 and Spring
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English version
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Reliability growth models
Reliability growth modelsReliability growth models
Reliability growth models
 
Agile Software Development Life Cycle
Agile Software Development Life CycleAgile Software Development Life Cycle
Agile Software Development Life Cycle
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
 
Smoke Testing
Smoke TestingSmoke Testing
Smoke Testing
 
Code smell overview
Code smell overviewCode smell overview
Code smell overview
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
SWE-401 - 2. Software Development life cycle (SDLC)
SWE-401 - 2. Software Development life cycle (SDLC)SWE-401 - 2. Software Development life cycle (SDLC)
SWE-401 - 2. Software Development life cycle (SDLC)
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Clean code
Clean codeClean code
Clean code
 
Model driven software engineering in practice book - chapter 7 - Developing y...
Model driven software engineering in practice book - chapter 7 - Developing y...Model driven software engineering in practice book - chapter 7 - Developing y...
Model driven software engineering in practice book - chapter 7 - Developing y...
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Clean Code
Clean CodeClean Code
Clean Code
 

Semelhante a Working Effectively With Legacy Code

Automated Testing with Databases
Automated Testing with DatabasesAutomated Testing with Databases
Automated Testing with Databases
Stephen Ritchie
 
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
 

Semelhante a Working Effectively 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"
 
Automated Testing with Databases
Automated Testing with DatabasesAutomated Testing with Databases
Automated Testing with Databases
 
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
 

Mais de Excella

Using Lean Thinking to Increase the Value of Agile
Using Lean Thinking to Increase the Value of AgileUsing Lean Thinking to Increase the Value of Agile
Using Lean Thinking to Increase the Value of Agile
Excella
 

Mais de Excella (20)

DCSUG - What's Really Going On? Observer Worksheet
DCSUG - What's Really Going On? Observer WorksheetDCSUG - What's Really Going On? Observer Worksheet
DCSUG - What's Really Going On? Observer Worksheet
 
DCSUG - We Are The Leaders We Have Been Waiting For by Lyssa Adkins
DCSUG - We Are The Leaders We Have Been Waiting For by Lyssa AdkinsDCSUG - We Are The Leaders We Have Been Waiting For by Lyssa Adkins
DCSUG - We Are The Leaders We Have Been Waiting For by Lyssa Adkins
 
DCSUG - Servant Leadership Handout
DCSUG - Servant Leadership HandoutDCSUG - Servant Leadership Handout
DCSUG - Servant Leadership Handout
 
DCSUG - Servant Leadership
DCSUG - Servant LeadershipDCSUG - Servant Leadership
DCSUG - Servant Leadership
 
DCSUG - Applying Analysis in an Agile World
DCSUG - Applying Analysis in an Agile WorldDCSUG - Applying Analysis in an Agile World
DCSUG - Applying Analysis in an Agile World
 
DCSUG - The Art and Practice of the Agile Leader
DCSUG - The Art and Practice of the Agile LeaderDCSUG - The Art and Practice of the Agile Leader
DCSUG - The Art and Practice of the Agile Leader
 
DCSUG - Finding Lean in Agile
DCSUG - Finding Lean in AgileDCSUG - Finding Lean in Agile
DCSUG - Finding Lean in Agile
 
DCSUG - Impact Mapping
DCSUG - Impact MappingDCSUG - Impact Mapping
DCSUG - Impact Mapping
 
DCSUG - Happiness: A Key Component of Agile
DCSUG - Happiness: A Key Component of AgileDCSUG - Happiness: A Key Component of Agile
DCSUG - Happiness: A Key Component of Agile
 
The Awkward Teenager of Testing
The Awkward Teenager of TestingThe Awkward Teenager of Testing
The Awkward Teenager of Testing
 
Let's Sharpen Your Agile Ax, It's Story Splitting Time
Let's Sharpen Your Agile Ax, It's Story Splitting TimeLet's Sharpen Your Agile Ax, It's Story Splitting Time
Let's Sharpen Your Agile Ax, It's Story Splitting Time
 
Managing for Happiness by Jurgen Appelo at DCSUG on 8/9/2016
Managing for Happiness by Jurgen Appelo at DCSUG on 8/9/2016Managing for Happiness by Jurgen Appelo at DCSUG on 8/9/2016
Managing for Happiness by Jurgen Appelo at DCSUG on 8/9/2016
 
The 7 Secrets of Highly Effective Retrospectives (DCSUG)
The 7 Secrets of Highly Effective Retrospectives (DCSUG)The 7 Secrets of Highly Effective Retrospectives (DCSUG)
The 7 Secrets of Highly Effective Retrospectives (DCSUG)
 
Get Your Productivity Game On!!
Get Your Productivity Game On!!Get Your Productivity Game On!!
Get Your Productivity Game On!!
 
How to Structure Multi Team Organizations
How to Structure Multi Team OrganizationsHow to Structure Multi Team Organizations
How to Structure Multi Team Organizations
 
Tactics to Kickstart Your Journey Toward DevOps
Tactics to Kickstart Your Journey Toward DevOpsTactics to Kickstart Your Journey Toward DevOps
Tactics to Kickstart Your Journey Toward DevOps
 
Intro to Mocking - DjangoCon 2015
Intro to Mocking - DjangoCon 2015Intro to Mocking - DjangoCon 2015
Intro to Mocking - DjangoCon 2015
 
Tactics to Kickstart Your Journey Toward Continuous Delivery
Tactics to Kickstart Your Journey Toward Continuous DeliveryTactics to Kickstart Your Journey Toward Continuous Delivery
Tactics to Kickstart Your Journey Toward Continuous Delivery
 
Using ansible vault to protect your secrets
Using ansible vault to protect your secretsUsing ansible vault to protect your secrets
Using ansible vault to protect your secrets
 
Using Lean Thinking to Increase the Value of Agile
Using Lean Thinking to Increase the Value of AgileUsing Lean Thinking to Increase the Value of Agile
Using Lean Thinking to Increase the Value of Agile
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 

Working Effectively 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