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

Destaque

чужинова нв, шляхтина он
чужинова нв, шляхтина ончужинова нв, шляхтина он
чужинова нв, шляхтина онchuginova
 
Destiny’s christmas speech
Destiny’s christmas speechDestiny’s christmas speech
Destiny’s christmas speechslrussell1
 
Scatol8 UUDD livello A_2
Scatol8 UUDD livello A_2Scatol8 UUDD livello A_2
Scatol8 UUDD livello A_2Scatol8
 
自己的遊戲自己寫 - 立志中學 2014/12/1 遊戲設計分享簡報
自己的遊戲自己寫 - 立志中學 2014/12/1 遊戲設計分享簡報自己的遊戲自己寫 - 立志中學 2014/12/1 遊戲設計分享簡報
自己的遊戲自己寫 - 立志中學 2014/12/1 遊戲設計分享簡報Mac Taylor
 
عرض الدرعية
عرض الدرعيةعرض الدرعية
عرض الدرعيةMHSEN_46
 
Coffee Shop Security Group Tool
Coffee Shop Security Group ToolCoffee Shop Security Group Tool
Coffee Shop Security Group Tooljoehack3r
 
[CLP] IT industry Day 2 - 4
[CLP] IT industry  Day 2 - 4[CLP] IT industry  Day 2 - 4
[CLP] IT industry Day 2 - 4Junhyuk Lee
 
Discover the power to be truly
Discover the power to be trulyDiscover the power to be truly
Discover the power to be trulytreasure4me
 
Presentatie VOV- retentie
Presentatie VOV- retentiePresentatie VOV- retentie
Presentatie VOV- retentieAerts_Sabine
 
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...SGK
 
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 EducativaMoniTa Rei
 

Destaque (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
 

Semelhante a Working with Legacy Code

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 Arnaud Bouchez
 
Create Your Own Starter Files
Create Your Own Starter FilesCreate Your Own Starter Files
Create Your Own Starter FilesEmily Lewis
 
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 SuccessInside Analysis
 
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"Inhacking
 
14 Habits of Great SQL Developers
14 Habits of Great SQL Developers14 Habits of Great SQL Developers
14 Habits of Great SQL DevelopersIke Ellis
 
Data Modeling for NoSQL
Data Modeling for NoSQLData Modeling for NoSQL
Data Modeling for NoSQLTony Tam
 
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 coreDan Poltawski
 
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 HoleNoam Kfir
 
14 Habits of Great SQL Developers
14 Habits of Great SQL Developers14 Habits of Great SQL Developers
14 Habits of Great SQL DevelopersIke Ellis
 
Intelligent content and Flare
Intelligent content and Flare Intelligent content and Flare
Intelligent content and Flare Denise Kadilak
 
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 AntipatternsEl Mahdi Benzekri
 
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 PuppetPuppet
 
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 2016Alex Theedom
 
Building a Collaborative Data Architecture
Building a Collaborative Data ArchitectureBuilding a Collaborative Data Architecture
Building a Collaborative Data ArchitectureDATAVERSITY
 
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 teamDaniel Gordon
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentationBhavin Gandhi
 
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 2018Mike Harris
 

Semelhante a 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
 
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"
 
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
 
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
 

Mais de 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
 

Último

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Último (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

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