SlideShare une entreprise Scribd logo
1  sur  29
ESCAPE THE LEGACY CODE MATRIX
Vimercate 11/02/2017
mario.russo@lastminute.com
@rmarioo
and sleep at night
@rmarioo
QUIZ: Legacy code ?
A) Code difficult to change
B) Inherited code difficult to change
C) Valuable code we’re afraid to change
2
@rmarioo
LEGACY CODE
3
• Is there a pragmatic approach ?
• Should I care about it ?
@rmarioo
Have you ever had these feelings ?
4
• Fear / Under pressure
.. so I do changes inside the existing code
• Nervous ( i depend on… )
“engaged” with debugger , complex infrastructure
• Unsafe
Did i broke something ? Is this working ?
• Resigned
“Edit and pray”
@rmarioo
You are in the Matrix
…. and you are feeding the monster !!!
Diagnosis…
5
Now take your choice..
@rmarioo 6
@rmarioo
The journey …of facing legacy code
7
UNDERSTAND REFACTORCOVER
Each step has a different target.
Focus only on that target !
CHANGE
@rmarioo
• Use it
… before looking at the code!
• Find one thing you know
1. look for keywords
2. and trace the actions backward
Understand: How ?
8
@rmarioo
• Sketch refactoring
• Keep reading someone else code
Understand: How ?
9
@rmarioo
Cover: the main target
10
• The 100% of test coverageCOVER
@rmarioo
Cover: where should i start ?
11
if condition1
….
….
if condition2
…..
…..
if condition3
…..
…..
else
…..
…..
else
…..
…..
else
…..
…..
Start from shortest
to deepest branch
@rmarioo
Cover: test the unknown
12
We assume to know what the code is supposed
to do
… but what if we don’t ?
• Test name ???
• Expected result ???
@rmarioo
Cover: Exploratory testing
13
1. Write a test named “x”
2. Set any expected result
3. Run it and get a Failure
java.lang.AssertionError: expected:<null> but was:<plain text>
4. Copy the text and make it pass
5. Give a better name
@rmarioo
Shortcut: “Delimit your territory”
14
Extract the code you want to change in a separate
section
- Smaller problem to solve
- Quicker way to the coverage
@rmarioo
Cover: Legacy code dilemma
15
CHANGE
CODE
HAVE
TEST IN
PLACE
@rmarioo
… some special licences
16
• Changes allowed only by IDE
refactoring
• Do not bother with code quality now
@rmarioo
Example : Subclass and override
1
7
public class A {
public void do1(…) {
user = session.getAttribute(“user”);
...
}
public class ATest
{
@Test
public void do1WhenLogged() { }
private class TestableA extends A
{
@Override
protected boolean isLogged()
{
return true
}
}
} public void do1(…) {
...
logged = isLogged(“mario")
}
protected Boolean isLogged(..)
TEST CODE SOURCE CODE
@rmarioo
Modify phase: two targets
18
REFACTOR CHANGE
@rmarioo
LET A TEST GUIDE US …
HARD TO CREATE
OR MAKE IT PASS ?
REFACTOR
APPLY THE
CHANGE
ADD A TEST
@rmarioo
Refactor: where to start ?
20
if condition1
….
….
if condition2
…..
…..
if condition3
…..
…..
else
…..
…..
else
…..
…..
else
…..
…..
From deepest branch
@rmarioo
Yak shaving ..
21
@rmarioo
Pair programming can help!
22
• N: What are you doing?
• D: I am doing x and y and .. z
• N: Let’s choose one and complete it !
Write down x , y and z in the todo list
Single task editing allows to Getting things done
@rmarioo
Adding a new feature: a common mistake
23
“Let’s put new feature inside this existing method
because it should happen at the same time”
Problem : … test old and new code together
@rmarioo
Ex. adding new feature: "Sprout class"
24
1.
public void do1()
{
…
// new Feature(..).apply(…)
}
2. TDD
public class Feature
{
public void apply(…)
{
…
}
}
3.
public void do1()
{
…
new Feature(..).apply(…)
}
@rmarioo
Pragmatic refactoring
25
• Stop when the change is easy to apply
• Effort proportional to code “liveness”
@rmarioo
Don’t repeat yourself!
26
• Split screen vertically TDD
• Continuous testing plugin
• Use shortcuts instead of repeating actions
• Small commits / steps
@rmarioo
Smells —> refactor —> steps & shortcuts
27
Show me the code !
https://github.com/rmarioo/smells-to-refactoring
@rmarioo
References
28
Books and publications
• Working Effectively with Legacy Code: Michael Feathers
• Refactoring: Improving the Design of Existing Code
• Sandro Mancuso – Testing and refactoring legacy code
• THE CODE WHISPERER - J. B. Rainsberger
Github projects
• Ugly trivia J. B. Rainsberger
• Videostore Robert Cecil Martin ( Uncle bob )
• Smells-to-refactoring Mario Russo
Thank you

Contenu connexe

Tendances

Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the DomainVictor Rentea
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best PracticesTheo Jungeblut
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithVictor Rentea
 
Clean Code - Writing code for human
Clean Code - Writing code for humanClean Code - Writing code for human
Clean Code - Writing code for humanNETKO Solution
 
Don't Be Mocked by your Mocks - Best Practices using Mocks
Don't Be Mocked by your Mocks - Best Practices using MocksDon't Be Mocked by your Mocks - Best Practices using Mocks
Don't Be Mocked by your Mocks - Best Practices using MocksVictor Rentea
 
Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignIrwansyah Irwansyah
 
Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerIgor Crvenov
 
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 versionsaber tabatabaee
 
Spring @Transactional Explained
Spring @Transactional ExplainedSpring @Transactional Explained
Spring @Transactional ExplainedVictor Rentea
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101Adam Culp
 
Pragmatic functional refactoring with java 8
Pragmatic functional refactoring with java 8Pragmatic functional refactoring with java 8
Pragmatic functional refactoring with java 8RichardWarburton
 
Code Smells and Its type (With Example)
Code Smells and Its type (With Example)Code Smells and Its type (With Example)
Code Smells and Its type (With Example)Anshul Vinayak
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code SmellsMario Sangiorgio
 
Working Effectively with Legacy Code
Working Effectively with Legacy CodeWorking Effectively with Legacy Code
Working Effectively with Legacy Codeslicklash
 
No Onions, No Tiers - An Introduction to Vertical Slice Architecture by Bill ...
No Onions, No Tiers - An Introduction to Vertical Slice Architecture by Bill ...No Onions, No Tiers - An Introduction to Vertical Slice Architecture by Bill ...
No Onions, No Tiers - An Introduction to Vertical Slice Architecture by Bill ...Alex Cachia
 
Conway's law revisited - Architectures for an effective IT
Conway's law revisited - Architectures for an effective ITConway's law revisited - Architectures for an effective IT
Conway's law revisited - Architectures for an effective ITUwe Friedrichsen
 
Software Craftsmanship - Code Smells - Dispensables
Software Craftsmanship - Code Smells - DispensablesSoftware Craftsmanship - Code Smells - Dispensables
Software Craftsmanship - Code Smells - DispensablesRajat Singla
 
Unit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityUnit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityVictor Rentea
 

Tendances (20)

Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the Domain
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best Practices
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
 
Clean Code - Writing code for human
Clean Code - Writing code for humanClean Code - Writing code for human
Clean Code - Writing code for human
 
Don't Be Mocked by your Mocks - Best Practices using Mocks
Don't Be Mocked by your Mocks - Best Practices using MocksDon't Be Mocked by your Mocks - Best Practices using Mocks
Don't Be Mocked by your Mocks - Best Practices using Mocks
 
Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven Design
 
Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin Fowler
 
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
 
Spring @Transactional Explained
Spring @Transactional ExplainedSpring @Transactional Explained
Spring @Transactional Explained
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101
 
Pragmatic functional refactoring with java 8
Pragmatic functional refactoring with java 8Pragmatic functional refactoring with java 8
Pragmatic functional refactoring with java 8
 
Refactoring
RefactoringRefactoring
Refactoring
 
Code Smells and Its type (With Example)
Code Smells and Its type (With Example)Code Smells and Its type (With Example)
Code Smells and Its type (With Example)
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Working Effectively with Legacy Code
Working Effectively with Legacy CodeWorking Effectively with Legacy Code
Working Effectively with Legacy Code
 
No Onions, No Tiers - An Introduction to Vertical Slice Architecture by Bill ...
No Onions, No Tiers - An Introduction to Vertical Slice Architecture by Bill ...No Onions, No Tiers - An Introduction to Vertical Slice Architecture by Bill ...
No Onions, No Tiers - An Introduction to Vertical Slice Architecture by Bill ...
 
Conway's law revisited - Architectures for an effective IT
Conway's law revisited - Architectures for an effective ITConway's law revisited - Architectures for an effective IT
Conway's law revisited - Architectures for an effective IT
 
Software Craftsmanship - Code Smells - Dispensables
Software Craftsmanship - Code Smells - DispensablesSoftware Craftsmanship - Code Smells - Dispensables
Software Craftsmanship - Code Smells - Dispensables
 
Unit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityUnit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of Purity
 
Clean Code
Clean CodeClean Code
Clean Code
 

Similaire à Escape the legacy code matrix - Vimercate

Undefined behaviour in the standard template library
Undefined behaviour in the standard template libraryUndefined behaviour in the standard template library
Undefined behaviour in the standard template librarySandor Dargo
 
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteClean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteVictor Rentea
 
Decompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 PresentationDecompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 PresentationJames Hamilton
 
Clean Code - The Next Chapter
Clean Code - The Next ChapterClean Code - The Next Chapter
Clean Code - The Next ChapterVictor Rentea
 
Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987乐群 陈
 
JDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
JDD 2016 - Sebastian Malaca - You Dont Need Unit TestsJDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
JDD 2016 - Sebastian Malaca - You Dont Need Unit TestsPROIDEA
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy CodeNaresh Jain
 
Maintainable code
Maintainable codeMaintainable code
Maintainable codeRiverGlide
 
Writing clean code in C# and .NET
Writing clean code in C# and .NETWriting clean code in C# and .NET
Writing clean code in C# and .NETDror Helper
 
Test-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptxTest-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptxVictor Rentea
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in JavaVadym Lotar
 
Mitigating Java Deserialization attacks from within the JVM (improved version)
Mitigating Java Deserialization attacks from within the JVM (improved version)Mitigating Java Deserialization attacks from within the JVM (improved version)
Mitigating Java Deserialization attacks from within the JVM (improved version)Apostolos Giannakidis
 
KillrChat Data Modeling
KillrChat Data ModelingKillrChat Data Modeling
KillrChat Data ModelingDuyhai Doan
 
Metaprogramming Rails
Metaprogramming RailsMetaprogramming Rails
Metaprogramming RailsJustus Eapen
 
Core java interview questions1
Core java interview questions1Core java interview questions1
Core java interview questions1Lahari Reddy
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questionsRohit Singh
 
Professional Code Reviews - Bogdan Gusiev
Professional Code Reviews - Bogdan GusievProfessional Code Reviews - Bogdan Gusiev
Professional Code Reviews - Bogdan GusievRuby Meditation
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010Rich Helton
 

Similaire à Escape the legacy code matrix - Vimercate (20)

Entering the matrix
Entering the matrixEntering the matrix
Entering the matrix
 
Undefined behaviour in the standard template library
Undefined behaviour in the standard template libraryUndefined behaviour in the standard template library
Undefined behaviour in the standard template library
 
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteClean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
 
Decompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 PresentationDecompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 Presentation
 
Clean Code - The Next Chapter
Clean Code - The Next ChapterClean Code - The Next Chapter
Clean Code - The Next Chapter
 
Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987Compiler2016 by abcdabcd987
Compiler2016 by abcdabcd987
 
JDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
JDD 2016 - Sebastian Malaca - You Dont Need Unit TestsJDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
JDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
 
Clean code
Clean codeClean code
Clean code
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Maintainable code
Maintainable codeMaintainable code
Maintainable code
 
Writing clean code in C# and .NET
Writing clean code in C# and .NETWriting clean code in C# and .NET
Writing clean code in C# and .NET
 
Test-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptxTest-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptx
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
 
Mitigating Java Deserialization attacks from within the JVM (improved version)
Mitigating Java Deserialization attacks from within the JVM (improved version)Mitigating Java Deserialization attacks from within the JVM (improved version)
Mitigating Java Deserialization attacks from within the JVM (improved version)
 
KillrChat Data Modeling
KillrChat Data ModelingKillrChat Data Modeling
KillrChat Data Modeling
 
Metaprogramming Rails
Metaprogramming RailsMetaprogramming Rails
Metaprogramming Rails
 
Core java interview questions1
Core java interview questions1Core java interview questions1
Core java interview questions1
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questions
 
Professional Code Reviews - Bogdan Gusiev
Professional Code Reviews - Bogdan GusievProfessional Code Reviews - Bogdan Gusiev
Professional Code Reviews - Bogdan Gusiev
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
 

Dernier

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyAnusha Are
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 

Dernier (20)

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 

Escape the legacy code matrix - Vimercate

  • 1. ESCAPE THE LEGACY CODE MATRIX Vimercate 11/02/2017 mario.russo@lastminute.com @rmarioo and sleep at night
  • 2. @rmarioo QUIZ: Legacy code ? A) Code difficult to change B) Inherited code difficult to change C) Valuable code we’re afraid to change 2
  • 3. @rmarioo LEGACY CODE 3 • Is there a pragmatic approach ? • Should I care about it ?
  • 4. @rmarioo Have you ever had these feelings ? 4 • Fear / Under pressure .. so I do changes inside the existing code • Nervous ( i depend on… ) “engaged” with debugger , complex infrastructure • Unsafe Did i broke something ? Is this working ? • Resigned “Edit and pray”
  • 5. @rmarioo You are in the Matrix …. and you are feeding the monster !!! Diagnosis… 5 Now take your choice..
  • 7. @rmarioo The journey …of facing legacy code 7 UNDERSTAND REFACTORCOVER Each step has a different target. Focus only on that target ! CHANGE
  • 8. @rmarioo • Use it … before looking at the code! • Find one thing you know 1. look for keywords 2. and trace the actions backward Understand: How ? 8
  • 9. @rmarioo • Sketch refactoring • Keep reading someone else code Understand: How ? 9
  • 10. @rmarioo Cover: the main target 10 • The 100% of test coverageCOVER
  • 11. @rmarioo Cover: where should i start ? 11 if condition1 …. …. if condition2 ….. ….. if condition3 ….. ….. else ….. ….. else ….. ….. else ….. ….. Start from shortest to deepest branch
  • 12. @rmarioo Cover: test the unknown 12 We assume to know what the code is supposed to do … but what if we don’t ? • Test name ??? • Expected result ???
  • 13. @rmarioo Cover: Exploratory testing 13 1. Write a test named “x” 2. Set any expected result 3. Run it and get a Failure java.lang.AssertionError: expected:<null> but was:<plain text> 4. Copy the text and make it pass 5. Give a better name
  • 14. @rmarioo Shortcut: “Delimit your territory” 14 Extract the code you want to change in a separate section - Smaller problem to solve - Quicker way to the coverage
  • 15. @rmarioo Cover: Legacy code dilemma 15 CHANGE CODE HAVE TEST IN PLACE
  • 16. @rmarioo … some special licences 16 • Changes allowed only by IDE refactoring • Do not bother with code quality now
  • 17. @rmarioo Example : Subclass and override 1 7 public class A { public void do1(…) { user = session.getAttribute(“user”); ... } public class ATest { @Test public void do1WhenLogged() { } private class TestableA extends A { @Override protected boolean isLogged() { return true } } } public void do1(…) { ... logged = isLogged(“mario") } protected Boolean isLogged(..) TEST CODE SOURCE CODE
  • 18. @rmarioo Modify phase: two targets 18 REFACTOR CHANGE
  • 19. @rmarioo LET A TEST GUIDE US … HARD TO CREATE OR MAKE IT PASS ? REFACTOR APPLY THE CHANGE ADD A TEST
  • 20. @rmarioo Refactor: where to start ? 20 if condition1 …. …. if condition2 ….. ….. if condition3 ….. ….. else ….. ….. else ….. ….. else ….. ….. From deepest branch
  • 22. @rmarioo Pair programming can help! 22 • N: What are you doing? • D: I am doing x and y and .. z • N: Let’s choose one and complete it ! Write down x , y and z in the todo list Single task editing allows to Getting things done
  • 23. @rmarioo Adding a new feature: a common mistake 23 “Let’s put new feature inside this existing method because it should happen at the same time” Problem : … test old and new code together
  • 24. @rmarioo Ex. adding new feature: "Sprout class" 24 1. public void do1() { … // new Feature(..).apply(…) } 2. TDD public class Feature { public void apply(…) { … } } 3. public void do1() { … new Feature(..).apply(…) }
  • 25. @rmarioo Pragmatic refactoring 25 • Stop when the change is easy to apply • Effort proportional to code “liveness”
  • 26. @rmarioo Don’t repeat yourself! 26 • Split screen vertically TDD • Continuous testing plugin • Use shortcuts instead of repeating actions • Small commits / steps
  • 27. @rmarioo Smells —> refactor —> steps & shortcuts 27 Show me the code ! https://github.com/rmarioo/smells-to-refactoring
  • 28. @rmarioo References 28 Books and publications • Working Effectively with Legacy Code: Michael Feathers • Refactoring: Improving the Design of Existing Code • Sandro Mancuso – Testing and refactoring legacy code • THE CODE WHISPERER - J. B. Rainsberger Github projects • Ugly trivia J. B. Rainsberger • Videostore Robert Cecil Martin ( Uncle bob ) • Smells-to-refactoring Mario Russo