SlideShare ist ein Scribd-Unternehmen logo
1 von 70
Downloaden Sie, um offline zu lesen
el Legacy vino
para quedarse
Toño de la Torre
DevFest Asturias 2019 -- 16.11.2019
Hi!
I’m Toñode la Torre
Software Developer at Codesai
@adelatorrefoss
2
GDG Asturias
https://twitter.com/GdgAsturias/status/794227008360300544
https://twitter.com/citipa/status/794227272970567680
https://twitter.com/GdgAsturias/status/768133121673928704
3
¿What is legacy
code?
1
What is legacy
code?
▸ Code we’ve gotten from someone else.
▸ Tangled, unintelligible structure, code that you
have to change but don't really understand.
▸ Difficult-to-change code that we don’t
understand.
▸ “The sort of code you just wish would die”.
6
“ To me, legacy code is
simply code without tests.
Michael C. Feathers
7
Code without tests
“Code without tests is bad code. It doesn't matter
how well written it is; it doesn't matter how pretty or
object-oriented or well-encapsulated it is.
With tests, we can change the behavior of our
code quickly and verifiably. Without them, we
really don't know if our code is getting better or
worse.”
8
confidence
Being able to confidently
make changes in any code
base.
9
What are
legacy
projects?
2
Are there more
legacy than before?
source
team
time
budget
12
Team3
Why is this
work so hard for
teams?
Fear of make changes
“
Although our first joy of
programming been
intense, the misery of
dealing with legacy code is
often sufficient to
extinguish that flame.
Robert C. Martin
15
retain talent
is hard in
legacy
“If it ain't broke, don't fix it”
(aka “add a new elseif at the end”)
And the big ball of mud was born.
How code becomes
so poor?
17
How to write good code?
(option A)
Managers or Technical Leads set a bunch of rules or fix an
architecture.
Is mandatory to everybody to follow these rules.
Someone, usually the Tech Lead review all code (via merge
request) to check if everybody is following the “agreement”.
18
How to write good code?
(option A)
(SPOILER!)
It fails
19
How to write good code?
(option B)
Instead let’s learn.
What’s bad code?
20
Smell the code4
Code Smells
Code structures that reflects problems on the code
base. Usually indicating design flaws.
A code smell can be an easy target to start
improving the code.
22
Code Smells
Duplicate code
Comments (deodorant)
Long method
Large class
Long parameter list
Primitive obsession
Data clumps
23
Switch statements
Shotgun surgery
Divergent Change
Feature Envy
Message chains
Code Smells & Refactorings
There are refactorings techniques that might
be used to remove a given code smell.
24
Code Smells
& Design
It's not enough to detect that your
code has code smells (design
problems).
You also need to know what good
design is, to know how to improve
your code.
25
How to
technically face
legacy code?
5
Reasons to change
software
1. Add feature
2. Fix bug
3. Improve design
4. Optimizing resource usage
Change behavior vs Preserve behavior
27
Edit and
Pray
vs
Cover and
Modify
28
Edit and Pray
Usually, we have to preserve much more behavior
than create new one.
But, how much behavior is in risk for one change?
We have to mitigate that risk, options:
- be conservative: “add an if sentence, don’t
create a new method” (we have fear)
The Code starts to ROT
29
Cover and Modify
1. Cover with test first (aka regression testing)
creating a safety net.
Cover with tests act as a software vise.
2. Refactor to make place (preserving behavior).
3. Make the change.
30
“
31
Pretty Code &
Pretty Design
In legacy code is something that we arrive
at in discrete steps.
Some of the steps to make changes involve
making some code slightly uglier.
Best could be the enemy of better.
32
Remember TDD
basic cycle
33
Focus
Focus in the problem
Focus in the solution
Focus in the solution quality
34
Correlation between
Internal Quality and
Productivity
how easy is to find the code?
how easy is to understand the code?
how easy is to change this code?
how easy is to test my changes?
35
Software
Economics
36
Dependency
problem
Much legacy code work involves breaking
dependencies so that change can be
easier.
6
The Legacy
Code
Dilemma
When we change code, we should
have tests in place.
To put tests in place, we often have
to change code.
38
Break dependencies with conservative and
safe refactorings.
Be conservative means that, we might end
up making the code look a little poorer in
that area.
Be conservative
39
The Legacy Code
Change Algorithm
1. Identify change points.
2. Find test points.
3. Break dependencies.
4. Write tests.
5. Make changes and refactor.
40
Reasons to break
dependencies
1. Sensing : to sense effects
2. Separation : to run a piece of code into
a test harness
41
Show me the
code
7
A classic dependency
class MarsLander {
private DataBase dataBase;
MarsLander(DataBase dataBase) {
this.dataBase = dataBase;
}
void openParachute() {
Command command = new Command("open-parachute");
dataBase.save(command);
}
}
44
class MarsLanderTest {
@Test
void open_parachute_smoothly() {
MarsLander.DataBase dataBase = mock(MarsLander.DataBase.class);
MarsLander marsLander = new MarsLander(dataBase);
marsLander.openParachute();
Command expectedCommand = new Command("open-parachute");
Mockito.verify(dataBase).save(expectedCommand);
}
}
45
A complicated dependency
46
class MarsRover {
void move(int x, int y) {
Command command = new Command("move", x, y);
// Connect with a communications satellite
SpaceSatellite satellite = SatelliteFactory.createABigOne();
satellite.sendCommand(command);
}
}
47
class MarsRover {
void move(int x, int y) {
Command command = new Command("move", x, y);
// Connect with a communications satellite
sendToSatellite(command);
}
protected void sendToSatellite(Command command) {
SpaceSatellite satellite = SatelliteFactory.createABigOne();
satellite.sendCommand(command);
}
}
48
class MarsRoverTest {
class MarsRoverSpy extends MarsRover {
Command commandSent;
@Override
protected void sendToSatellite(Command command) {
commandSent = command;
}
}
@Test
void move_to_some_coordinates() {
MarsRoverSpy marsRover = new MarsRoverSpy();
marsRover.move(1, 1);
Command command = new Command("move", 1, 1);
assertEquals(command, marsRover.commandSent);
}
}
49
team again8
How to make the project
interesting for the teams?
The daily work with Legacy should be a challenge, an
opportunity to learn something new.
51
Code Smells
& Design
It's not enough to detect that your
code has code smells (design
problems).
You also need to know what good
design is, to know how to improve
your code.
52
How to learn along the way?
- Training in Technical skills
- Code smells, TDD, Refactoring, Design, Working with
Legacy, ...
- Knowledge Diffusion
- Pair programming
- On boarding process
- Technical concerns process
- Crystalizing Knowledge
53
How to learn along the way?
- Changing Habits
- Meaning of Done
- Quality First Mindset
- Coaching Through Pair Programming
- Deliberate Practice
- Have a shared team culture and a process to change it
- Creating Critical Mass
- All Team Product Owning
54
Principles9
Clean Code
A set of rules, principles and heuristics easy to
understand by all the team.
Understandability makes change, extension and
maintenance possible.
56
The 4 Rules of Simple
Design
57
Kent Beck
SOLID
1. Single Responsibility Principle (SRP)
2. Open Closed Principle (OCP)
3. Liskov Substitution Principle (LSP)
4. Interface Segregation Principle (ISP)
5. Dependency Inversion Principle (DIP)
58
Hexagonal
Architecture
(Ports &
Adapters)
10
How does good design looks
like?
A good design must support evolution
A good design must be testable
60
Ports & Adapters: Goal
“Allow an application to equally be driven by users,
programs, automated test or batch scripts, and to be
developed and tested in isolation from its eventual
run-time devices and databases.”
Alistair Cockburn
61
Ports & Adapters
Model is isolated, connected to
external world through interfaces
(ports) .
Those interfaces are
implemented in objects
(adapters) that translate the
application domain concepts
onto an appropriate technical
implementation.
62
class MarsRover {
void move(int x, int y) {
Command command = new Command("move", x, y);
// Connect with a communications satellite
sendToSatellite(command);
}
protected void sendToSatellite(Command command) {
SpaceSatellite satellite = SatelliteFactory.createABigOne();
satellite.sendCommand(command);
}
}
63
But in the real
world?
11
Some experiences
- “Developers or POs, you should decide”
- New JS frameworks fans!
- Not everybody is enthusiastic with the
“learning” idea.
65
"Crossing the Chasm by Geoffrey Moore" by Chris Matts is licensed under CC BY 4.0
Comunidades de Necesidad &
Comunidades de Soluciones
Communities of Need & Community of Solutions
Antonio de la Torre
@adelatorrefoss
A different approach to Crossing the Chasm
CAS 2016 Vitoria, 1 de Noviembre de 2016
Bibliography
Working Effectively with Legacy Code. Michael C. Feathers
Refactoring. Martin Fowler
Refactoring (second ed.). Martin Fowler
68
69
Preserve
your
business!
Thanks!
▸ Toño
▸ @adelatorrefoss
Credits
Special thanks to all the people who made and released these
awesome resources for free:
▸ Presentation template by SlidesCarnival
▸ Illustrations by Sergei Tikhonov
▸ Photographs by Unsplash
70

Weitere ähnliche Inhalte

Ähnlich wie 20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para quedarse)

Growing Software and Growing Ourselves
Growing Software and Growing OurselvesGrowing Software and Growing Ourselves
Growing Software and Growing OurselvesDaniel Parkin
 
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
 
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
 
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
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review ProcessDr. Syed Hassan Amin
 
Clean Infrastructure as Code
Clean Infrastructure as CodeClean Infrastructure as Code
Clean Infrastructure as CodeQAware GmbH
 
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019Paulo Clavijo
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMax Kleiner
 
Open Source Power Tools - Opensouthcode 2018-06-02
Open Source Power Tools - Opensouthcode 2018-06-02Open Source Power Tools - Opensouthcode 2018-06-02
Open Source Power Tools - Opensouthcode 2018-06-02Jorge Hidalgo
 
Structured Software Design
Structured Software DesignStructured Software Design
Structured Software DesignGiorgio Zoppi
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agilityelliando dias
 
Writing code for people
Writing code for peopleWriting code for people
Writing code for peopleAlexey Ivanov
 
JavaOne 2017 CON2902 - Java Code Inspection and Testing Power Tools
JavaOne 2017 CON2902 - Java Code Inspection and Testing Power ToolsJavaOne 2017 CON2902 - Java Code Inspection and Testing Power Tools
JavaOne 2017 CON2902 - Java Code Inspection and Testing Power ToolsJorge Hidalgo
 
Refactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopRefactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopMax Kleiner
 
11. Lecture 19 Code standards and review.ppt
11. Lecture 19 Code standards and review.ppt11. Lecture 19 Code standards and review.ppt
11. Lecture 19 Code standards and review.pptMaddalaSeshu
 

Ähnlich wie 20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para quedarse) (20)

Growing Software and Growing Ourselves
Growing Software and Growing OurselvesGrowing Software and Growing Ourselves
Growing Software and Growing Ourselves
 
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
 
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
 
Tech talks#6: Code Refactoring
Tech talks#6: Code RefactoringTech talks#6: Code Refactoring
Tech talks#6: Code Refactoring
 
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
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
 
Code review
Code reviewCode review
Code review
 
Clean Infrastructure as Code
Clean Infrastructure as CodeClean Infrastructure as Code
Clean Infrastructure as Code
 
Code quality
Code quality Code quality
Code quality
 
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleiner
 
Open Source Power Tools - Opensouthcode 2018-06-02
Open Source Power Tools - Opensouthcode 2018-06-02Open Source Power Tools - Opensouthcode 2018-06-02
Open Source Power Tools - Opensouthcode 2018-06-02
 
Structured Software Design
Structured Software DesignStructured Software Design
Structured Software Design
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
Quick Intro to Clean Coding
Quick Intro to Clean CodingQuick Intro to Clean Coding
Quick Intro to Clean Coding
 
Writing code for people
Writing code for peopleWriting code for people
Writing code for people
 
CQRS recepies
CQRS recepiesCQRS recepies
CQRS recepies
 
JavaOne 2017 CON2902 - Java Code Inspection and Testing Power Tools
JavaOne 2017 CON2902 - Java Code Inspection and Testing Power ToolsJavaOne 2017 CON2902 - Java Code Inspection and Testing Power Tools
JavaOne 2017 CON2902 - Java Code Inspection and Testing Power Tools
 
Refactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopRefactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_Workshop
 
11. Lecture 19 Code standards and review.ppt
11. Lecture 19 Code standards and review.ppt11. Lecture 19 Code standards and review.ppt
11. Lecture 19 Code standards and review.ppt
 

Mehr von Antonio de la Torre Fernández

ITSmf Astur18 La agilidad como motor de cambio en las organizaciones
ITSmf Astur18 La agilidad como motor de cambio en las organizacionesITSmf Astur18 La agilidad como motor de cambio en las organizaciones
ITSmf Astur18 La agilidad como motor de cambio en las organizacionesAntonio de la Torre Fernández
 
Taller Agile para emprendedores InnovAstur y Oviedo Emprende
Taller Agile para emprendedores InnovAstur y Oviedo EmprendeTaller Agile para emprendedores InnovAstur y Oviedo Emprende
Taller Agile para emprendedores InnovAstur y Oviedo EmprendeAntonio de la Torre Fernández
 
Discusiones y decisiones: herramientas para la efectividad
Discusiones y decisiones: herramientas para la efectividadDiscusiones y decisiones: herramientas para la efectividad
Discusiones y decisiones: herramientas para la efectividadAntonio de la Torre Fernández
 
CAS2016 Community of Need & Community of Solutions (December 1st 2016)
CAS2016 Community of Need & Community of Solutions (December 1st 2016)CAS2016 Community of Need & Community of Solutions (December 1st 2016)
CAS2016 Community of Need & Community of Solutions (December 1st 2016)Antonio de la Torre Fernández
 
CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...
CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...
CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...Antonio de la Torre Fernández
 
ALE14 - Involving UX and Design in Agile Development #sketchnoting
ALE14 - Involving UX and Design in Agile Development #sketchnotingALE14 - Involving UX and Design in Agile Development #sketchnoting
ALE14 - Involving UX and Design in Agile Development #sketchnotingAntonio de la Torre Fernández
 
Where i put my business logic - Greach 2014, Madrid, Spain
Where i put my business logic  - Greach 2014, Madrid, SpainWhere i put my business logic  - Greach 2014, Madrid, Spain
Where i put my business logic - Greach 2014, Madrid, SpainAntonio de la Torre Fernández
 
CAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestades
CAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestadesCAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestades
CAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestadesAntonio de la Torre Fernández
 
Nuevos negocios y empleos basados en el Software y el Conocimiento Libre
Nuevos negocios y empleos basados en el Software y el Conocimiento LibreNuevos negocios y empleos basados en el Software y el Conocimiento Libre
Nuevos negocios y empleos basados en el Software y el Conocimiento LibreAntonio de la Torre Fernández
 

Mehr von Antonio de la Torre Fernández (16)

ITSmf Astur18 La agilidad como motor de cambio en las organizaciones
ITSmf Astur18 La agilidad como motor de cambio en las organizacionesITSmf Astur18 La agilidad como motor de cambio en las organizaciones
ITSmf Astur18 La agilidad como motor de cambio en las organizaciones
 
Taller Agile para emprendedores InnovAstur y Oviedo Emprende
Taller Agile para emprendedores InnovAstur y Oviedo EmprendeTaller Agile para emprendedores InnovAstur y Oviedo Emprende
Taller Agile para emprendedores InnovAstur y Oviedo Emprende
 
Discusiones y decisiones: herramientas para la efectividad
Discusiones y decisiones: herramientas para la efectividadDiscusiones y decisiones: herramientas para la efectividad
Discusiones y decisiones: herramientas para la efectividad
 
CAS2016 Community of Need & Community of Solutions (December 1st 2016)
CAS2016 Community of Need & Community of Solutions (December 1st 2016)CAS2016 Community of Need & Community of Solutions (December 1st 2016)
CAS2016 Community of Need & Community of Solutions (December 1st 2016)
 
El viaje de Angular1 a Angular2
El viaje de Angular1 a Angular2El viaje de Angular1 a Angular2
El viaje de Angular1 a Angular2
 
UX Agilista - UXSpain 2015
UX Agilista - UXSpain 2015UX Agilista - UXSpain 2015
UX Agilista - UXSpain 2015
 
CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...
CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...
CAS2014 - Integrando UX & Diseño en el Desarrollo Agil - La historia dos años...
 
¿Se puede implementar una Cultura Ágil?
¿Se puede implementar una Cultura Ágil?¿Se puede implementar una Cultura Ágil?
¿Se puede implementar una Cultura Ágil?
 
ALE - Why it's worth going?
ALE - Why it's worth going?ALE - Why it's worth going?
ALE - Why it's worth going?
 
ALE14 - Involving UX and Design in Agile Development #sketchnoting
ALE14 - Involving UX and Design in Agile Development #sketchnotingALE14 - Involving UX and Design in Agile Development #sketchnoting
ALE14 - Involving UX and Design in Agile Development #sketchnoting
 
Where i put my business logic - Greach 2014, Madrid, Spain
Where i put my business logic  - Greach 2014, Madrid, SpainWhere i put my business logic  - Greach 2014, Madrid, Spain
Where i put my business logic - Greach 2014, Madrid, Spain
 
A User Story - some ideas
A User Story - some ideasA User Story - some ideas
A User Story - some ideas
 
Mejoras CAS 2011
Mejoras CAS 2011Mejoras CAS 2011
Mejoras CAS 2011
 
CAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestades
CAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestadesCAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestades
CAS 2012. Agile en equipos mixtos: Diseño y Desarrollo. Amainando tempestades
 
Arquitectura en Alfresco
Arquitectura en AlfrescoArquitectura en Alfresco
Arquitectura en Alfresco
 
Nuevos negocios y empleos basados en el Software y el Conocimiento Libre
Nuevos negocios y empleos basados en el Software y el Conocimiento LibreNuevos negocios y empleos basados en el Software y el Conocimiento Libre
Nuevos negocios y empleos basados en el Software y el Conocimiento Libre
 

Kürzlich hochgeladen

A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 

Kürzlich hochgeladen (20)

A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 

20191116 DevFest 2019 The Legacy Code came to stay (El legacy vino para quedarse)

  • 1. el Legacy vino para quedarse Toño de la Torre DevFest Asturias 2019 -- 16.11.2019
  • 2. Hi! I’m Toñode la Torre Software Developer at Codesai @adelatorrefoss 2
  • 4.
  • 6. What is legacy code? ▸ Code we’ve gotten from someone else. ▸ Tangled, unintelligible structure, code that you have to change but don't really understand. ▸ Difficult-to-change code that we don’t understand. ▸ “The sort of code you just wish would die”. 6
  • 7. “ To me, legacy code is simply code without tests. Michael C. Feathers 7
  • 8. Code without tests “Code without tests is bad code. It doesn't matter how well written it is; it doesn't matter how pretty or object-oriented or well-encapsulated it is. With tests, we can change the behavior of our code quickly and verifiably. Without them, we really don't know if our code is getting better or worse.” 8
  • 9. confidence Being able to confidently make changes in any code base. 9
  • 11. Are there more legacy than before?
  • 13. Team3
  • 14. Why is this work so hard for teams? Fear of make changes
  • 15. “ Although our first joy of programming been intense, the misery of dealing with legacy code is often sufficient to extinguish that flame. Robert C. Martin 15
  • 17. “If it ain't broke, don't fix it” (aka “add a new elseif at the end”) And the big ball of mud was born. How code becomes so poor? 17
  • 18. How to write good code? (option A) Managers or Technical Leads set a bunch of rules or fix an architecture. Is mandatory to everybody to follow these rules. Someone, usually the Tech Lead review all code (via merge request) to check if everybody is following the “agreement”. 18
  • 19. How to write good code? (option A) (SPOILER!) It fails 19
  • 20. How to write good code? (option B) Instead let’s learn. What’s bad code? 20
  • 22. Code Smells Code structures that reflects problems on the code base. Usually indicating design flaws. A code smell can be an easy target to start improving the code. 22
  • 23. Code Smells Duplicate code Comments (deodorant) Long method Large class Long parameter list Primitive obsession Data clumps 23 Switch statements Shotgun surgery Divergent Change Feature Envy Message chains
  • 24. Code Smells & Refactorings There are refactorings techniques that might be used to remove a given code smell. 24
  • 25. Code Smells & Design It's not enough to detect that your code has code smells (design problems). You also need to know what good design is, to know how to improve your code. 25
  • 27. Reasons to change software 1. Add feature 2. Fix bug 3. Improve design 4. Optimizing resource usage Change behavior vs Preserve behavior 27
  • 29. Edit and Pray Usually, we have to preserve much more behavior than create new one. But, how much behavior is in risk for one change? We have to mitigate that risk, options: - be conservative: “add an if sentence, don’t create a new method” (we have fear) The Code starts to ROT 29
  • 30. Cover and Modify 1. Cover with test first (aka regression testing) creating a safety net. Cover with tests act as a software vise. 2. Refactor to make place (preserving behavior). 3. Make the change. 30
  • 32. Pretty Code & Pretty Design In legacy code is something that we arrive at in discrete steps. Some of the steps to make changes involve making some code slightly uglier. Best could be the enemy of better. 32
  • 34. Focus Focus in the problem Focus in the solution Focus in the solution quality 34
  • 35. Correlation between Internal Quality and Productivity how easy is to find the code? how easy is to understand the code? how easy is to change this code? how easy is to test my changes? 35
  • 37. Dependency problem Much legacy code work involves breaking dependencies so that change can be easier. 6
  • 38. The Legacy Code Dilemma When we change code, we should have tests in place. To put tests in place, we often have to change code. 38
  • 39. Break dependencies with conservative and safe refactorings. Be conservative means that, we might end up making the code look a little poorer in that area. Be conservative 39
  • 40. The Legacy Code Change Algorithm 1. Identify change points. 2. Find test points. 3. Break dependencies. 4. Write tests. 5. Make changes and refactor. 40
  • 41. Reasons to break dependencies 1. Sensing : to sense effects 2. Separation : to run a piece of code into a test harness 41
  • 44. class MarsLander { private DataBase dataBase; MarsLander(DataBase dataBase) { this.dataBase = dataBase; } void openParachute() { Command command = new Command("open-parachute"); dataBase.save(command); } } 44
  • 45. class MarsLanderTest { @Test void open_parachute_smoothly() { MarsLander.DataBase dataBase = mock(MarsLander.DataBase.class); MarsLander marsLander = new MarsLander(dataBase); marsLander.openParachute(); Command expectedCommand = new Command("open-parachute"); Mockito.verify(dataBase).save(expectedCommand); } } 45
  • 47. class MarsRover { void move(int x, int y) { Command command = new Command("move", x, y); // Connect with a communications satellite SpaceSatellite satellite = SatelliteFactory.createABigOne(); satellite.sendCommand(command); } } 47
  • 48. class MarsRover { void move(int x, int y) { Command command = new Command("move", x, y); // Connect with a communications satellite sendToSatellite(command); } protected void sendToSatellite(Command command) { SpaceSatellite satellite = SatelliteFactory.createABigOne(); satellite.sendCommand(command); } } 48
  • 49. class MarsRoverTest { class MarsRoverSpy extends MarsRover { Command commandSent; @Override protected void sendToSatellite(Command command) { commandSent = command; } } @Test void move_to_some_coordinates() { MarsRoverSpy marsRover = new MarsRoverSpy(); marsRover.move(1, 1); Command command = new Command("move", 1, 1); assertEquals(command, marsRover.commandSent); } } 49
  • 51. How to make the project interesting for the teams? The daily work with Legacy should be a challenge, an opportunity to learn something new. 51
  • 52. Code Smells & Design It's not enough to detect that your code has code smells (design problems). You also need to know what good design is, to know how to improve your code. 52
  • 53. How to learn along the way? - Training in Technical skills - Code smells, TDD, Refactoring, Design, Working with Legacy, ... - Knowledge Diffusion - Pair programming - On boarding process - Technical concerns process - Crystalizing Knowledge 53
  • 54. How to learn along the way? - Changing Habits - Meaning of Done - Quality First Mindset - Coaching Through Pair Programming - Deliberate Practice - Have a shared team culture and a process to change it - Creating Critical Mass - All Team Product Owning 54
  • 56. Clean Code A set of rules, principles and heuristics easy to understand by all the team. Understandability makes change, extension and maintenance possible. 56
  • 57. The 4 Rules of Simple Design 57 Kent Beck
  • 58. SOLID 1. Single Responsibility Principle (SRP) 2. Open Closed Principle (OCP) 3. Liskov Substitution Principle (LSP) 4. Interface Segregation Principle (ISP) 5. Dependency Inversion Principle (DIP) 58
  • 60. How does good design looks like? A good design must support evolution A good design must be testable 60
  • 61. Ports & Adapters: Goal “Allow an application to equally be driven by users, programs, automated test or batch scripts, and to be developed and tested in isolation from its eventual run-time devices and databases.” Alistair Cockburn 61
  • 62. Ports & Adapters Model is isolated, connected to external world through interfaces (ports) . Those interfaces are implemented in objects (adapters) that translate the application domain concepts onto an appropriate technical implementation. 62
  • 63. class MarsRover { void move(int x, int y) { Command command = new Command("move", x, y); // Connect with a communications satellite sendToSatellite(command); } protected void sendToSatellite(Command command) { SpaceSatellite satellite = SatelliteFactory.createABigOne(); satellite.sendCommand(command); } } 63
  • 64. But in the real world? 11
  • 65. Some experiences - “Developers or POs, you should decide” - New JS frameworks fans! - Not everybody is enthusiastic with the “learning” idea. 65
  • 66. "Crossing the Chasm by Geoffrey Moore" by Chris Matts is licensed under CC BY 4.0
  • 67. Comunidades de Necesidad & Comunidades de Soluciones Communities of Need & Community of Solutions Antonio de la Torre @adelatorrefoss A different approach to Crossing the Chasm CAS 2016 Vitoria, 1 de Noviembre de 2016
  • 68. Bibliography Working Effectively with Legacy Code. Michael C. Feathers Refactoring. Martin Fowler Refactoring (second ed.). Martin Fowler 68
  • 70. Credits Special thanks to all the people who made and released these awesome resources for free: ▸ Presentation template by SlidesCarnival ▸ Illustrations by Sergei Tikhonov ▸ Photographs by Unsplash 70