SlideShare a Scribd company logo
Refactor your code: when, why and how?
2Confidential
Nacho Cougil
• Senior Software Engineerat Dynatrace
• TDD &cleancode fan
• Founderof the Barcelona Java Users Group ( BarcelonaJUG ) & co-founderof the
Java andJVMBarcelona Conference
( JBCNConf)
• Father, formermountain marathonrunner 😅
@icougil
WhoamI?
Confidential 3
• What is legacy code?
• What is refactor?
• Why refactor is {so }important?
• When to refactor code?
• Tips for refactoring
• How to do it?
• Recap
Agenda
Confidential 4
Whatislegacycode?
• “Legacy code is everythingthat is not tested“
MichaelFeathers
• “Today, I stopped refactoring. Todaymyapplication became
legacy”
VictorRentea
• “Valuable code weare afraid to change”
J.B.Rainsberger
Confidential 5
• …do not understand what a particular code does and why?
• ... wehave to workwith themaximum care because we
understand that there can be manyproblems (surgeon
mode)
• ... weare afraid to touch the code
Haveyoufelt thatsensation?
Confidential 6
Whatisrefactoring?
• Refactoring is a disciplined technique for restructuring
an existing body of code, altering its internal structure
without changing its external behaviour
• Refactoring is intended to improve the design,
structure, and/or implementation of
the software (its non-functional attributes), while
preserving its functionality
• So the main goal is… about:
• Improving maintainability
• Better readability
• Reduce complexity
• https://en.wikipedia.org/wiki/Code_refactoring
• “A change made to the internal structure of software to
make it easier to understand and cheaper to modify
without changing its observable behaviour”
Martin Fowler
7Confidential
Whyis refactoring important?
http://martinfowler.com/bliki/DesignStaminaHypothesis.htm
l
http://at4qa.blogspot.com/2010/06/code-refactoring-once-you-meet-it.html
8Confidential
• Broken windows theory (1982)
• “A successful strategy for preventing vandalism, according
to the book's authors, is to address the problems when
they are small”
• Minorcode smells mightlead to completely
degenerated functions, classes, packages software
became complicated &more difficult to maintain
Whyis refactoring important?
https://en.wikipedia.org/wiki/Broken_windows_theory
9Confidential
• Preparatory
• BeforeI need to add a newfeatureor to fix a bug
• As whendoing anexperiment -orcooking- probably
you may needto arrangethescenarioproperly (ex:
preparing theenvironment, collecting theproducts you
need, etc)
• As whentravelling,wemay needto checkthe map and
find thebest routebefore moving
Whento refactor?
10Confidential
• Comprehension
• Whenweneedto understand the codebeforewe
change it
• Do I understand what this code does? Should I refactor it?
• “We are moving our understanding from our head into the
code itself“
WardCunningham
• Whenthe codegetsclearer,wecanfind things on the design
that wecould not seebefore
Whento refactor?
11Confidential
• Litter-pickup
• The code is doing something in a bad way (repeated code, high
complexity, etc)
• BoyScoutrule:“always leave the campground cleaner than you found it”
• Small things ALWAYS matters!
• Renaming avariable tomake it more understandable
• Creating amethod that encapsulates a logic
• Building a new class that holds a particularbehaviour
• Remove unnecessary comments /dead code
Whento refactor?
12Confidential
• Planned
• Weneed a dedicated timeto get theircode base into
a better state for the future
• It maybe a sign that teams areworkingto pay off an
unpaid technical debt
• VSdoing it continuouslyas part of yournaturalflow of
programming(ex: TDD,pair programming)
Whento refactor?
13Confidential
• Long-term
• The effort tomake the change is significantly higher
(weeks vs hours/few days?)
• Theeffort of changingthe status of the code is better than
rewriting it (ex: fix some dependencies inour project,
replace an existing library, etc)
• A dedicated team to workon it VSgradually workon the
problem
Whento refactor?
14Confidential
• Continuously
• Include refactoring as a normalactivity in yourday-to-day
job
• Less effort to do it insmall steps than inbig ones
• More easily adapted when following XP practices (ex:
TDD, codereviews, CI,etc)
• “Just do it”  fast feedback loop will makeyou
programfaster
Whento refactor?
Confidential 15
• Build a safety net that gives youtheconfidence to make
changes
• Workwith small steps &increments
• Keep the code simple (as muchas possible)
• Runyour tests ✅ after each change
• Review 👀 your code coverage
• Usethe tool 🛠 that could work {better }for you.Then,
master it!
Tips
Confidential 16
Tips- How to start?
Start testing from the shortest branch
Start refactoring fromthe deepest branch
Confidential 17
Catalogofrefactorings
• 60refactorings
• https://www.refactoring.com/catalog/
Confidential 18
But….how???
Confidential 19
Warning –Live coding!
Confidential 20
• Sandro Mancuso
• https://youtu.be/_NnElPO5BU0
• Dave Farley
• https://youtu.be/p-oWHEfXEVs
• Jason Gorman
• https://youtu.be/TSQVb2QoP2A
• Victor Rentea
• https://youtu.be/iOYsxBvMkLk
• NayanHajratwala
• https://youtu.be/1_X9ObRZkk4
Recommendedcontent
Confidential 21
• Importanceof refactoring
• Different typesof refactoring
• {Build &use }a safety net 🛠
• Usethe % coverage to guide 🛠 you
• Understand (&apply) the seam 🛠 technique
• Workwith small increments (useyour DVCS)
• Design yoursoftware with testability inmind
• Rememberthe boyscout rule! 😉
• Practice, practice &practice 🛠 again
Finalrecap
22Confidential
nacho@cougil.com
nacho.cougil@dynatrace.com
https://nacho.cougil.com
@icougil
I’d love 😍 to receive yourfeedback, please:
https://bit.ly/refactoring-feedback-nacho
Questions?
23Confidential
THANKYOU !
Ad

More Related Content

What's hot (20)

Extreme Programming (XP): Revisted
Extreme Programming (XP): RevistedExtreme Programming (XP): Revisted
Extreme Programming (XP): Revisted
Mike Harris
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
Gianluca Padovani
 
Adopting Devops , Stories from the trenches
Adopting Devops , Stories from the trenchesAdopting Devops , Stories from the trenches
Adopting Devops , Stories from the trenches
Kris Buytaert
 
Being a professional software tester
Being a professional software testerBeing a professional software tester
Being a professional software tester
Anton Keks
 
TDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDTDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDD
David Rodenas
 
TDD refresher
TDD refresherTDD refresher
TDD refresher
Kerry Buckley
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
Gianluca Padovani
 
Test drive on driven development process
Test drive on driven development processTest drive on driven development process
Test drive on driven development process
Muralidharan Deenathayalan
 
The View - 30 proven Lotuscript tips
The View - 30 proven Lotuscript tipsThe View - 30 proven Lotuscript tips
The View - 30 proven Lotuscript tips
Bill Buchan
 
LCE12: Intro Training: Upstreaming 101
LCE12: Intro Training: Upstreaming 101LCE12: Intro Training: Upstreaming 101
LCE12: Intro Training: Upstreaming 101
Linaro
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
Lim Chanmann
 
Tdd practices
Tdd practicesTdd practices
Tdd practices
axykim00
 
Tdd com Java
Tdd com JavaTdd com Java
Tdd com Java
Rafael Miceli
 
Lessons learned with Bdd: a tutorial
Lessons learned with Bdd: a tutorialLessons learned with Bdd: a tutorial
Lessons learned with Bdd: a tutorial
Alan Richardson
 
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Victor Rentea
 
Tdd
TddTdd
Tdd
mahmoud ramadan
 
TDD = bra design?
TDD = bra design?TDD = bra design?
TDD = bra design?
Kjetil Klaussen
 
TDD and Simple Design Workshop - Session 1 - November 2018
TDD and Simple Design Workshop - Session 1 - November 2018TDD and Simple Design Workshop - Session 1 - November 2018
TDD and Simple Design Workshop - Session 1 - November 2018
Paulo Clavijo
 
Don't get blamed for your choices - Techorama 2019
Don't get blamed for your choices - Techorama 2019Don't get blamed for your choices - Techorama 2019
Don't get blamed for your choices - Techorama 2019
Hannes Lowette
 
Tdd
TddTdd
Tdd
Alexander Zaidel
 
Extreme Programming (XP): Revisted
Extreme Programming (XP): RevistedExtreme Programming (XP): Revisted
Extreme Programming (XP): Revisted
Mike Harris
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
Gianluca Padovani
 
Adopting Devops , Stories from the trenches
Adopting Devops , Stories from the trenchesAdopting Devops , Stories from the trenches
Adopting Devops , Stories from the trenches
Kris Buytaert
 
Being a professional software tester
Being a professional software testerBeing a professional software tester
Being a professional software tester
Anton Keks
 
TDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDTDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDD
David Rodenas
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
Gianluca Padovani
 
The View - 30 proven Lotuscript tips
The View - 30 proven Lotuscript tipsThe View - 30 proven Lotuscript tips
The View - 30 proven Lotuscript tips
Bill Buchan
 
LCE12: Intro Training: Upstreaming 101
LCE12: Intro Training: Upstreaming 101LCE12: Intro Training: Upstreaming 101
LCE12: Intro Training: Upstreaming 101
Linaro
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
Lim Chanmann
 
Tdd practices
Tdd practicesTdd practices
Tdd practices
axykim00
 
Lessons learned with Bdd: a tutorial
Lessons learned with Bdd: a tutorialLessons learned with Bdd: a tutorial
Lessons learned with Bdd: a tutorial
Alan Richardson
 
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Victor Rentea
 
TDD and Simple Design Workshop - Session 1 - November 2018
TDD and Simple Design Workshop - Session 1 - November 2018TDD and Simple Design Workshop - Session 1 - November 2018
TDD and Simple Design Workshop - Session 1 - November 2018
Paulo Clavijo
 
Don't get blamed for your choices - Techorama 2019
Don't get blamed for your choices - Techorama 2019Don't get blamed for your choices - Techorama 2019
Don't get blamed for your choices - Techorama 2019
Hannes Lowette
 

Similar to Refactor your code: when, why and how? (20)

Get your Project back in Shape!
Get your Project back in Shape!Get your Project back in Shape!
Get your Project back in Shape!
Joachim Tuchel
 
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)
Nacho Cougil
 
Devconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedDevconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developed
Alexander Makarov
 
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
ssusercaf6c1
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
Nacho Cougil
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech Week
Nacho Cougil
 
Refactoring in Software Reengineering .pptx
Refactoring in  Software Reengineering .pptxRefactoring in  Software Reengineering .pptx
Refactoring in Software Reengineering .pptx
itstehreem2830
 
TDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - OpensouthcodeTDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - Opensouthcode
Nacho Cougil
 
TDD - Seriously, try it - Codemotion (May '24)
TDD - Seriously, try it - Codemotion (May '24)TDD - Seriously, try it - Codemotion (May '24)
TDD - Seriously, try it - Codemotion (May '24)
Nacho Cougil
 
Code refactoring
Code refactoringCode refactoring
Code refactoring
Lalit Kale
 
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
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®
Hannes Lowette
 
Kku2011
Kku2011Kku2011
Kku2011
ทวิร พานิชสมบัติ
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
Einar Ingebrigtsen
 
Friday final test
Friday final testFriday final test
Friday final test
bcoder
 
It is a sunny day
It is a sunny dayIt is a sunny day
It is a sunny day
bcoder
 
Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...
Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...
Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...
Michel Buczynski
 
Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...
Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...
Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...
Chocolatey Software
 
It's XP, Stupid
It's XP, StupidIt's XP, Stupid
It's XP, Stupid
Mike Harris
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
Andrei KUCHARAVY
 
Get your Project back in Shape!
Get your Project back in Shape!Get your Project back in Shape!
Get your Project back in Shape!
Joachim Tuchel
 
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)
Nacho Cougil
 
Devconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedDevconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developed
Alexander Makarov
 
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
ssusercaf6c1
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
Nacho Cougil
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech Week
Nacho Cougil
 
Refactoring in Software Reengineering .pptx
Refactoring in  Software Reengineering .pptxRefactoring in  Software Reengineering .pptx
Refactoring in Software Reengineering .pptx
itstehreem2830
 
TDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - OpensouthcodeTDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - Opensouthcode
Nacho Cougil
 
TDD - Seriously, try it - Codemotion (May '24)
TDD - Seriously, try it - Codemotion (May '24)TDD - Seriously, try it - Codemotion (May '24)
TDD - Seriously, try it - Codemotion (May '24)
Nacho Cougil
 
Code refactoring
Code refactoringCode refactoring
Code refactoring
Lalit Kale
 
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
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®
Hannes Lowette
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
Einar Ingebrigtsen
 
Friday final test
Friday final testFriday final test
Friday final test
bcoder
 
It is a sunny day
It is a sunny dayIt is a sunny day
It is a sunny day
bcoder
 
Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...
Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...
Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...
Michel Buczynski
 
Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...
Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...
Facilitating continuous delivery in a FinTech world with Salt, Jenkins, Nexus...
Chocolatey Software
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
Andrei KUCHARAVY
 
Ad

More from Nacho Cougil (9)

How John started to like TDD (instead of hating it) - TED talk
How John started to like TDD (instead of hating it) - TED talkHow John started to like TDD (instead of hating it) - TED talk
How John started to like TDD (instead of hating it) - TED talk
Nacho Cougil
 
How John started to like TDD (instead of hating it)
How John started to like TDD (instead of hating it)How John started to like TDD (instead of hating it)
How John started to like TDD (instead of hating it)
Nacho Cougil
 
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
Nacho Cougil
 
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
Nacho Cougil
 
Introduction to TDD
Introduction to TDDIntroduction to TDD
Introduction to TDD
Nacho Cougil
 
BarcelonaJUG at GDG summit
BarcelonaJUG at GDG summitBarcelonaJUG at GDG summit
BarcelonaJUG at GDG summit
Nacho Cougil
 
Be clean, my friend (Clean code review by BarcelonaJUG)
Be clean, my friend (Clean code review by BarcelonaJUG)Be clean, my friend (Clean code review by BarcelonaJUG)
Be clean, my friend (Clean code review by BarcelonaJUG)
Nacho Cougil
 
Gencat Notifier
Gencat NotifierGencat Notifier
Gencat Notifier
Nacho Cougil
 
Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...
Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...
Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...
Nacho Cougil
 
How John started to like TDD (instead of hating it) - TED talk
How John started to like TDD (instead of hating it) - TED talkHow John started to like TDD (instead of hating it) - TED talk
How John started to like TDD (instead of hating it) - TED talk
Nacho Cougil
 
How John started to like TDD (instead of hating it)
How John started to like TDD (instead of hating it)How John started to like TDD (instead of hating it)
How John started to like TDD (instead of hating it)
Nacho Cougil
 
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
Nacho Cougil
 
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
All you need is fast feedback loop, fast feedback loop, fast feedback loop is...
Nacho Cougil
 
Introduction to TDD
Introduction to TDDIntroduction to TDD
Introduction to TDD
Nacho Cougil
 
BarcelonaJUG at GDG summit
BarcelonaJUG at GDG summitBarcelonaJUG at GDG summit
BarcelonaJUG at GDG summit
Nacho Cougil
 
Be clean, my friend (Clean code review by BarcelonaJUG)
Be clean, my friend (Clean code review by BarcelonaJUG)Be clean, my friend (Clean code review by BarcelonaJUG)
Be clean, my friend (Clean code review by BarcelonaJUG)
Nacho Cougil
 
Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...
Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...
Seghismed - Disseny i desenvolupament d'un esquema criptogràfic per gestionar...
Nacho Cougil
 
Ad

Recently uploaded (20)

Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Top 10 IT Help Desk Outsourcing Services
Top 10 IT Help Desk Outsourcing ServicesTop 10 IT Help Desk Outsourcing Services
Top 10 IT Help Desk Outsourcing Services
Infrassist Technologies Pvt. Ltd.
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 

Refactor your code: when, why and how?

  • 1. Refactor your code: when, why and how?
  • 2. 2Confidential Nacho Cougil • Senior Software Engineerat Dynatrace • TDD &cleancode fan • Founderof the Barcelona Java Users Group ( BarcelonaJUG ) & co-founderof the Java andJVMBarcelona Conference ( JBCNConf) • Father, formermountain marathonrunner 😅 @icougil WhoamI?
  • 3. Confidential 3 • What is legacy code? • What is refactor? • Why refactor is {so }important? • When to refactor code? • Tips for refactoring • How to do it? • Recap Agenda
  • 4. Confidential 4 Whatislegacycode? • “Legacy code is everythingthat is not tested“ MichaelFeathers • “Today, I stopped refactoring. Todaymyapplication became legacy” VictorRentea • “Valuable code weare afraid to change” J.B.Rainsberger
  • 5. Confidential 5 • …do not understand what a particular code does and why? • ... wehave to workwith themaximum care because we understand that there can be manyproblems (surgeon mode) • ... weare afraid to touch the code Haveyoufelt thatsensation?
  • 6. Confidential 6 Whatisrefactoring? • Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behaviour • Refactoring is intended to improve the design, structure, and/or implementation of the software (its non-functional attributes), while preserving its functionality • So the main goal is… about: • Improving maintainability • Better readability • Reduce complexity • https://en.wikipedia.org/wiki/Code_refactoring • “A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behaviour” Martin Fowler
  • 8. 8Confidential • Broken windows theory (1982) • “A successful strategy for preventing vandalism, according to the book's authors, is to address the problems when they are small” • Minorcode smells mightlead to completely degenerated functions, classes, packages software became complicated &more difficult to maintain Whyis refactoring important? https://en.wikipedia.org/wiki/Broken_windows_theory
  • 9. 9Confidential • Preparatory • BeforeI need to add a newfeatureor to fix a bug • As whendoing anexperiment -orcooking- probably you may needto arrangethescenarioproperly (ex: preparing theenvironment, collecting theproducts you need, etc) • As whentravelling,wemay needto checkthe map and find thebest routebefore moving Whento refactor?
  • 10. 10Confidential • Comprehension • Whenweneedto understand the codebeforewe change it • Do I understand what this code does? Should I refactor it? • “We are moving our understanding from our head into the code itself“ WardCunningham • Whenthe codegetsclearer,wecanfind things on the design that wecould not seebefore Whento refactor?
  • 11. 11Confidential • Litter-pickup • The code is doing something in a bad way (repeated code, high complexity, etc) • BoyScoutrule:“always leave the campground cleaner than you found it” • Small things ALWAYS matters! • Renaming avariable tomake it more understandable • Creating amethod that encapsulates a logic • Building a new class that holds a particularbehaviour • Remove unnecessary comments /dead code Whento refactor?
  • 12. 12Confidential • Planned • Weneed a dedicated timeto get theircode base into a better state for the future • It maybe a sign that teams areworkingto pay off an unpaid technical debt • VSdoing it continuouslyas part of yournaturalflow of programming(ex: TDD,pair programming) Whento refactor?
  • 13. 13Confidential • Long-term • The effort tomake the change is significantly higher (weeks vs hours/few days?) • Theeffort of changingthe status of the code is better than rewriting it (ex: fix some dependencies inour project, replace an existing library, etc) • A dedicated team to workon it VSgradually workon the problem Whento refactor?
  • 14. 14Confidential • Continuously • Include refactoring as a normalactivity in yourday-to-day job • Less effort to do it insmall steps than inbig ones • More easily adapted when following XP practices (ex: TDD, codereviews, CI,etc) • “Just do it”  fast feedback loop will makeyou programfaster Whento refactor?
  • 15. Confidential 15 • Build a safety net that gives youtheconfidence to make changes • Workwith small steps &increments • Keep the code simple (as muchas possible) • Runyour tests ✅ after each change • Review 👀 your code coverage • Usethe tool 🛠 that could work {better }for you.Then, master it! Tips
  • 16. Confidential 16 Tips- How to start? Start testing from the shortest branch Start refactoring fromthe deepest branch
  • 17. Confidential 17 Catalogofrefactorings • 60refactorings • https://www.refactoring.com/catalog/
  • 20. Confidential 20 • Sandro Mancuso • https://youtu.be/_NnElPO5BU0 • Dave Farley • https://youtu.be/p-oWHEfXEVs • Jason Gorman • https://youtu.be/TSQVb2QoP2A • Victor Rentea • https://youtu.be/iOYsxBvMkLk • NayanHajratwala • https://youtu.be/1_X9ObRZkk4 Recommendedcontent
  • 21. Confidential 21 • Importanceof refactoring • Different typesof refactoring • {Build &use }a safety net 🛠 • Usethe % coverage to guide 🛠 you • Understand (&apply) the seam 🛠 technique • Workwith small increments (useyour DVCS) • Design yoursoftware with testability inmind • Rememberthe boyscout rule! 😉 • Practice, practice &practice 🛠 again Finalrecap
  • 22. 22Confidential [email protected] [email protected] https://nacho.cougil.com @icougil I’d love 😍 to receive yourfeedback, please: https://bit.ly/refactoring-feedback-nacho Questions?

Editor's Notes

  • #5: (It‘s about information and safety)
  • #7: make it easier to understand and cheaper to modify (without changing the observable behavior of the software)
  • #8: Design stamina hypothesis: - at some point new features requires more time to see how to fit into the existing code base - by putting our effort into a good internal design, we increase the stamina of the software effort, allowing us to go faster for longer
  • #9: Broken windows theory (1982): a criminological theory that states that visible signs of crime, anti-social behavior, and civil disorder create an urban environment that encourages further crime and disorder, including serious crimes.
  • #20: https://github.com/sandromancuso/trip-service-kata.git - Seam: “A seam is a place where you can alter behavior in your program without editing in that place.” Excerpt From: Michael C. Feathers. “Working Effectively with Legacy Code”.
  • #21: GOOST >> TDD learn, understand & apply Refactoring to patterns >> shows incremental changes made to transition from a problematic start to the pattern-based end point
  • #23: Nacho