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

Mais conteĂșdo relacionado

Semelhante a Entering the matrix

Stop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principlesStop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principlesEdorian
 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Editionjexp
 
sitBRU - The Hitchhikers Guide to the Legacy
sitBRU - The Hitchhikers Guide to the LegacysitBRU - The Hitchhikers Guide to the Legacy
sitBRU - The Hitchhikers Guide to the LegacyLaurens van Rijn
 
20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...
20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...
20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...Antonio de la Torre FernĂĄndez
 
Maintainable code
Maintainable codeMaintainable code
Maintainable codeRiverGlide
 
Escape the legacy code matrix - Vimercate
Escape the legacy code matrix - VimercateEscape the legacy code matrix - Vimercate
Escape the legacy code matrix - VimercateMario Russo
 
Showing How Security Has (And Hasn't) Improved, After Ten Years Of Trying
Showing How Security Has (And Hasn't) Improved, After Ten Years Of TryingShowing How Security Has (And Hasn't) Improved, After Ten Years Of Trying
Showing How Security Has (And Hasn't) Improved, After Ten Years Of TryingDan Kaminsky
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019Paulo Clavijo
 
sitHVR - The Hitchhikers Guide to the Legacy
sitHVR - The Hitchhikers Guide to the LegacysitHVR - The Hitchhikers Guide to the Legacy
sitHVR - The Hitchhikers Guide to the LegacyLaurens van Rijn
 
Planning JavaScript and Ajax for larger teams
Planning JavaScript and Ajax for larger teamsPlanning JavaScript and Ajax for larger teams
Planning JavaScript and Ajax for larger teamsChristian Heilmann
 
Matlab for a computational PhD
Matlab for a computational PhDMatlab for a computational PhD
Matlab for a computational PhDAlbanLevy
 
Stop fearing legacy code
Stop fearing legacy codeStop fearing legacy code
Stop fearing legacy codeYaki Koren
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy CodeAndrea Polci
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testingGianluca Padovani
 
How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....Mike Harris
 
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
 
Test Driving Legacy Code Mini Workshop
Test Driving Legacy Code Mini WorkshopTest Driving Legacy Code Mini Workshop
Test Driving Legacy Code Mini WorkshopFernando Cuenca
 
TDD in Python With Pytest
TDD in Python With PytestTDD in Python With Pytest
TDD in Python With PytestEddy Reyes
 
Software Development Essential Skills
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential SkillsJohn Choi
 

Semelhante a Entering the matrix (20)

Clean Code 2
Clean Code 2Clean Code 2
Clean Code 2
 
Stop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principlesStop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principles
 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Edition
 
sitBRU - The Hitchhikers Guide to the Legacy
sitBRU - The Hitchhikers Guide to the LegacysitBRU - The Hitchhikers Guide to the Legacy
sitBRU - The Hitchhikers Guide to the Legacy
 
20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...
20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...
20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para queda...
 
Maintainable code
Maintainable codeMaintainable code
Maintainable code
 
Escape the legacy code matrix - Vimercate
Escape the legacy code matrix - VimercateEscape the legacy code matrix - Vimercate
Escape the legacy code matrix - Vimercate
 
Showing How Security Has (And Hasn't) Improved, After Ten Years Of Trying
Showing How Security Has (And Hasn't) Improved, After Ten Years Of TryingShowing How Security Has (And Hasn't) Improved, After Ten Years Of Trying
Showing How Security Has (And Hasn't) Improved, After Ten Years Of Trying
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
 
sitHVR - The Hitchhikers Guide to the Legacy
sitHVR - The Hitchhikers Guide to the LegacysitHVR - The Hitchhikers Guide to the Legacy
sitHVR - The Hitchhikers Guide to the Legacy
 
Planning JavaScript and Ajax for larger teams
Planning JavaScript and Ajax for larger teamsPlanning JavaScript and Ajax for larger teams
Planning JavaScript and Ajax for larger teams
 
Matlab for a computational PhD
Matlab for a computational PhDMatlab for a computational PhD
Matlab for a computational PhD
 
Stop fearing legacy code
Stop fearing legacy codeStop fearing legacy code
Stop fearing legacy code
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy Code
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
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.....How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....
 
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
 
Test Driving Legacy Code Mini Workshop
Test Driving Legacy Code Mini WorkshopTest Driving Legacy Code Mini Workshop
Test Driving Legacy Code Mini Workshop
 
TDD in Python With Pytest
TDD in Python With PytestTDD in Python With Pytest
TDD in Python With Pytest
 
Software Development Essential Skills
Software Development Essential SkillsSoftware Development Essential Skills
Software Development Essential Skills
 

Mais de Francesco Garavaglia

Mais de Francesco Garavaglia (7)

Introduction to DevOps
Introduction to DevOpsIntroduction to DevOps
Introduction to DevOps
 
Workshop - cqrs brief introduction
Workshop - cqrs brief introductionWorkshop - cqrs brief introduction
Workshop - cqrs brief introduction
 
CQRS recepies
CQRS recepiesCQRS recepies
CQRS recepies
 
IOC in Unity
IOC in Unity  IOC in Unity
IOC in Unity
 
IOC in unity
IOC in unityIOC in unity
IOC in unity
 
Work shop eventstorming
Work shop  eventstormingWork shop  eventstorming
Work shop eventstorming
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 

Último

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfWilly Marroquin (WillyDevNET)
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 

Último (20)

Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] đŸ„ Women's Abortion Clinic in T...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 

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?
  • 7.
  • 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