SlideShare a Scribd company logo
ENTERING THE
MATRIX
Work with Legacy Code
F. Garavaglia
08/2017
v. 1.0
o Photographer
o High-Aggressive-I-eat-you-
German-Shepherd-
Protected-by
I’m Francesco Garavaglia
o over 10 years of experience in IT consulting
companies.
o Took part in large scale projects (Energy
Markets, Bank, Insurance)
o Pay attention to Software architecture and
Business value
Agenda
◦ What is “Legacy Code”?
◦ See how it’s deep the white rabbit’s hole
◦ Code Samples
WHAT’S “LEGACY CODE”?
What problems are we trying to solve?
1
What’s “Legacy Code”?
Quiz: Legacy Code?
A. Code difficult to change
B. Inherited code difficult to change
C. Valuable code we’re afraid to change
What’s “Legacy Code”?
 Is there a Pragmatic Approach?
 Should I care about it?
 What about your feelings?
Entering the matrix
What’s “Legacy Code”?
o Nervous (I depend on… )
“engaged” with debugger , complex infrastructure
o Fear / Under pressure
.. so I do changes inside the existing code
o Unsafe
Did i broke something ? Is this working ?
o Resigned
“Edit and pray”
What’s “Legacy Code”?
o My Diagnosis:
You are in Matrix:
Then, you have to
take a pill
Cover and
Modify
Edit and
Pray
THE WHITE RABBIT’S HOLE
See how it is deep and dark
2
The white rabbit’s hole
We need a map for this journey: how
can we face with Legacy code?
UNDERSTAND COVER REFACTOR CHANGE
Each step has different target: focus
on 1 at times.
The white rabbit’s hole: HOW
• Use it before looking at the code
• Find one thing you know
1. look for keywords
2. and trace the actions backward
• Sketch refactoring
• Keep reading someone else code
The white rabbit’s hole: COVER
You need 100% of test coverage
if condition1
….
….
if condition2
…..
…..
if condition3
…..
…..
else
…..
…..
else
…..
…..
else
…..
…..
Start from shortest
to deepest branch
COVER: test the unknown
assume to know what the code is
supposed to do
… but what if we don’t ?
•Test name ???
•Expected result ???
COVER: test the unknown
1. Write a test named “x”
2. Set any expected result
3. Run it and get a Failure
4. Copy the text and make it pass
5. Give a better name
COVER: test the unknown
Extract the code you want to change in a
separate section
- Smaller problem to solve
- Quicker way to the coverage
EXAMPLE: Subclass and Override
public class A {
public void do1(…) {
user = session.getAttribute(“user”);
...
}
}
Souce Code
public void do1(…) {
...
logged = isLogged(“mario")
}
protected Boolean isLogged(..)
public class ATest
{
[TestMEthod]
public void do1WhenLogged() { }
private class TestableA : A
{
protected override boolean isLogged()
{
return true
}
}
}
Test Code
The white rabbit’s hole: REFACTOR
• Related to change phase
Start
End
Add a Test
Hard to
Create or
Make it Pass?
Refactor
Apply the
change
The white rabbit’s hole: REFACTOR
• Start from the deepest brach
if condition1
….
….
if condition2
…..
…..
if condition3
…..
…..
else
…..
…..
else
…..
…..
else
…..
…..
The white rabbit’s hole: CHANGE
Adding a new feature: Common mistake
“Let’s put new feature inside this existing
method because it should happen at the
same time”
Problem : … test old and new code together
EXAMPLE: Adding a new feature
public void do1()
{
…
// new Feature(..).apply(…)
}
Souce Code
public class Feature
{
public void apply(…)
{
…
}
}
public void do1()
{
…
new Feature(..).apply(…)
}
Productive Code
TDD
DON’T REPEAT YOURSELF
◦ Split screen vertically TDD
◦ Continuous testing plugin
◦ Use shortcuts instead of repeating actions
◦ Small commits / steps
Thanks
Thank you for your time
Francesco.garavaglia@gmail.com
REFERENCES
• Refactoring: Improving the Design of Existing Code
https://www.amazon.it/Refactoring-Improving-Design-Existing-
Code/dp/0201485672/ref=sr_1_1?ie=UTF8&qid=1504536816&sr=8-
1&keywords=Refactoring%3A+Improving+the+Design+of+Existing+Code
• M. Feathers- Working Effectively with Legacy Code
https://www.amazon.it/Working-Effectively-Legacy-Michael-
Feathers/dp/0131177052/ref=sr_1_1?s=english-books&ie=UTF8&qid=1504536861&sr=1-
1&keywords=Working+Effectively+with+Legacy+Code%3A+Michael+Feathers

More Related Content

PPTX
Pen Testing Development
PPTX
DevSecCon SG 2018 Fabian Presentation Slides
PDF
DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply rem...
PDF
Raising the Bar
PDF
Structured Software Design
ODP
New Ideas for Old Code - Greach
PDF
What is ATT&CK coverage, anyway? Breadth and depth analysis with Atomic Red Team
Pen Testing Development
DevSecCon SG 2018 Fabian Presentation Slides
DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply rem...
Raising the Bar
Structured Software Design
New Ideas for Old Code - Greach
What is ATT&CK coverage, anyway? Breadth and depth analysis with Atomic Red Team

Similar to Entering the matrix (20)

PDF
Clean Code 2
PPTX
Stop wasting-time-by-applying-clean-code-principles
PPTX
Refactoring, 2nd Edition
PPSX
sitBRU - The Hitchhikers Guide to the Legacy
PDF
20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...
KEY
Maintainable code
PPTX
Escape the legacy code matrix - Vimercate
PPTX
Showing How Security Has (And Hasn't) Improved, After Ten Years Of Trying
PDF
TDD and Simple Design Workshop - Session 1 - March 2019
PPSX
sitHVR - The Hitchhikers Guide to the Legacy
PPT
Planning JavaScript and Ajax for larger teams
PDF
Matlab for a computational PhD
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
PPTX
Stop fearing legacy code
PDF
Working With Legacy Code
PDF
Tdd is not about testing
PPTX
How I Learned to Stop Worrying and Love Legacy Code.....
PPTX
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
PPTX
Test Driving Legacy Code Mini Workshop
PDF
TDD in Python With Pytest
Clean Code 2
Stop wasting-time-by-applying-clean-code-principles
Refactoring, 2nd Edition
sitBRU - The Hitchhikers Guide to the Legacy
20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...
Maintainable code
Escape the legacy code matrix - Vimercate
Showing How Security Has (And Hasn't) Improved, After Ten Years Of Trying
TDD and Simple Design Workshop - Session 1 - March 2019
sitHVR - The Hitchhikers Guide to the Legacy
Planning JavaScript and Ajax for larger teams
Matlab for a computational PhD
Writing Better Code - Helping Developers make Decisions.pptx
Stop fearing legacy code
Working With Legacy Code
Tdd is not about testing
How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
Test Driving Legacy Code Mini Workshop
TDD in Python With Pytest
Ad

More from Francesco Garavaglia (7)

PPTX
Introduction to DevOps
PPTX
Workshop - cqrs brief introduction
PDF
CQRS recepies
PDF
IOC in Unity
PDF
IOC in unity
PDF
Work shop eventstorming
PDF
Workshop unit test
Introduction to DevOps
Workshop - cqrs brief introduction
CQRS recepies
IOC in Unity
IOC in unity
Work shop eventstorming
Workshop unit test
Ad

Recently uploaded (20)

PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
ai tools demonstartion for schools and inter college
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Online Work Permit System for Fast Permit Processing
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
history of c programming in notes for students .pptx
PDF
Nekopoi APK 2025 free lastest update
PDF
top salesforce developer skills in 2025.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
System and Network Administration Chapter 2
2025 Textile ERP Trends: SAP, Odoo & Oracle
How to Choose the Right IT Partner for Your Business in Malaysia
Which alternative to Crystal Reports is best for small or large businesses.pdf
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
ai tools demonstartion for schools and inter college
Design an Analysis of Algorithms II-SECS-1021-03
How Creative Agencies Leverage Project Management Software.pdf
Design an Analysis of Algorithms I-SECS-1021-03
Softaken Excel to vCard Converter Software.pdf
Online Work Permit System for Fast Permit Processing
How to Migrate SBCGlobal Email to Yahoo Easily
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
history of c programming in notes for students .pptx
Nekopoi APK 2025 free lastest update
top salesforce developer skills in 2025.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Operating system designcfffgfgggggggvggggggggg
System and Network Administration Chapter 2

Entering the matrix

  • 1. ENTERING THE MATRIX Work with Legacy Code F. Garavaglia 08/2017 v. 1.0
  • 2. o Photographer o High-Aggressive-I-eat-you- German-Shepherd- Protected-by I’m Francesco Garavaglia o over 10 years of experience in IT consulting companies. o Took part in large scale projects (Energy Markets, Bank, Insurance) o Pay attention to Software architecture and Business value
  • 3. Agenda ◦ What is “Legacy Code”? ◦ See how it’s deep the white rabbit’s hole ◦ Code Samples
  • 4. WHAT’S “LEGACY CODE”? What problems are we trying to solve? 1
  • 5. What’s “Legacy Code”? Quiz: Legacy Code? A. Code difficult to change B. Inherited code difficult to change C. Valuable code we’re afraid to change
  • 6. What’s “Legacy Code”?  Is there a Pragmatic Approach?  Should I care about it?  What about your feelings?
  • 8. What’s “Legacy Code”? o Nervous (I depend on… ) “engaged” with debugger , complex infrastructure o Fear / Under pressure .. so I do changes inside the existing code o Unsafe Did i broke something ? Is this working ? o Resigned “Edit and pray”
  • 9. What’s “Legacy Code”? o My Diagnosis: You are in Matrix: Then, you have to take a pill
  • 11. THE WHITE RABBIT’S HOLE See how it is deep and dark 2
  • 12. The white rabbit’s hole We need a map for this journey: how can we face with Legacy code? UNDERSTAND COVER REFACTOR CHANGE Each step has different target: focus on 1 at times.
  • 13. The white rabbit’s hole: HOW • Use it before looking at the code • Find one thing you know 1. look for keywords 2. and trace the actions backward • Sketch refactoring • Keep reading someone else code
  • 14. The white rabbit’s hole: COVER You need 100% of test coverage if condition1 …. …. if condition2 ….. ….. if condition3 ….. ….. else ….. ….. else ….. ….. else ….. ….. Start from shortest to deepest branch
  • 15. COVER: test the unknown assume to know what the code is supposed to do … but what if we don’t ? •Test name ??? •Expected result ???
  • 16. COVER: test the unknown 1. Write a test named “x” 2. Set any expected result 3. Run it and get a Failure 4. Copy the text and make it pass 5. Give a better name
  • 17. COVER: test the unknown Extract the code you want to change in a separate section - Smaller problem to solve - Quicker way to the coverage
  • 18. EXAMPLE: Subclass and Override public class A { public void do1(…) { user = session.getAttribute(“user”); ... } } Souce Code public void do1(…) { ... logged = isLogged(“mario") } protected Boolean isLogged(..) public class ATest { [TestMEthod] public void do1WhenLogged() { } private class TestableA : A { protected override boolean isLogged() { return true } } } Test Code
  • 19. The white rabbit’s hole: REFACTOR • Related to change phase Start End Add a Test Hard to Create or Make it Pass? Refactor Apply the change
  • 20. The white rabbit’s hole: REFACTOR • Start from the deepest brach if condition1 …. …. if condition2 ….. ….. if condition3 ….. ….. else ….. ….. else ….. ….. else ….. …..
  • 21. The white rabbit’s hole: CHANGE Adding a new feature: Common mistake “Let’s put new feature inside this existing method because it should happen at the same time” Problem : … test old and new code together
  • 22. EXAMPLE: Adding a new feature public void do1() { … // new Feature(..).apply(…) } Souce Code public class Feature { public void apply(…) { … } } public void do1() { … new Feature(..).apply(…) } Productive Code TDD
  • 23. DON’T REPEAT YOURSELF ◦ Split screen vertically TDD ◦ Continuous testing plugin ◦ Use shortcuts instead of repeating actions ◦ Small commits / steps
  • 24. Thanks Thank you for your time Francesco.garavaglia@gmail.com
  • 25. REFERENCES • Refactoring: Improving the Design of Existing Code https://www.amazon.it/Refactoring-Improving-Design-Existing- Code/dp/0201485672/ref=sr_1_1?ie=UTF8&qid=1504536816&sr=8- 1&keywords=Refactoring%3A+Improving+the+Design+of+Existing+Code • M. Feathers- Working Effectively with Legacy Code https://www.amazon.it/Working-Effectively-Legacy-Michael- Feathers/dp/0131177052/ref=sr_1_1?s=english-books&ie=UTF8&qid=1504536861&sr=1- 1&keywords=Working+Effectively+with+Legacy+Code%3A+Michael+Feathers