SlideShare a Scribd company logo
1 of 58
Download to read offline
El Legacy vino para quedarse
(Legacy code came to stay)Toño de la Torre
@adelatorrefoss
Software Crafters
¿What is legacy
code?
1
@adelatorrefoss @codesaidev
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”.
4@adelatorrefoss @codesaidev
“ To me, legacy code is
simply code without tests.
Michael C. Feathers
5@adelatorrefoss @codesaidev
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.”
6@adelatorrefoss @codesaidev
confidence
Being able to confidently
make changes in any code
base.
7@adelatorrefoss @codesaidev
What are
legacy
projects?
2
@adelatorrefoss @codesaidev
Code that is hard to
change but still
makes money
@adelatorrefoss @codesaidev
source
+
team
10@adelatorrefoss @codesaidev
Team3
@adelatorrefoss @codesaidev
Why is it so
hard for teams?
@adelatorrefoss @codesaidev
frustration
13@adelatorrefoss @codesaidev
“
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
14@adelatorrefoss @codesaidev
retaining talent
is hard in
legacy projects
@adelatorrefoss @codesaidev
4 Previously, on...
@adelatorrefoss @codesaidev
“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 does code
becomes so hard?
17@adelatorrefoss @codesaidev
How to write good code?
(option A)
Managers or Technical Leads set a bunch of rules and/or
define an architecture.
It is mandatory that everyone follow these rules.
Someone, usually the Tech Lead, reviews all code (via
merge request) to check if everybody is following the
“agreement”.
18@adelatorrefoss @codesaidev
How to write good code?
(option A)
(SPOILER!)
It fails
19@adelatorrefoss @codesaidev
How to write good code?
(option B)
Instead let’s learn.
What’s bad code?
20
Smell the code5
@adelatorrefoss @codesaidev
Code Smells
Code structures that reflect problems on the
code base. Usually indicating design flaws.
A code smell can be an easy target to start
improving the code.
22@adelatorrefoss @codesaidev
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
@adelatorrefoss @codesaidev
How to
technically face
legacy code?
6
@adelatorrefoss @codesaidev
Reasons to change
software
1. Adding a feature
2. Fixing a bug
3. Improving the design of the system
4. Optimizing resource usage
Change behavior & Preserve behavior
25@adelatorrefoss @codesaidev
Edit and
Pray
vs
Cover and
Modify
26@adelatorrefoss @codesaidev
Cover and Modify
1. Cover with tests first (aka regression testing)
creating a safety net.
Tests act as a software vise.
2. Refactor to make place (preserving behavior).
3. Make the change.
27@adelatorrefoss @codesaidev
“
28@adelatorrefoss @codesaidev
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.
29@adelatorrefoss @codesaidev
Software
Economics
30@adelatorrefoss @codesaidev
Dependency
problem
Much legacy code work involves breaking
dependencies so that change can be
easier.
7
@adelatorrefoss @codesaidev
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.
32@adelatorrefoss @codesaidev
Break dependencies with conservative and
safe refactorings.
Being conservative means that, we might
end up making the code look a little poorer
in that area.
Be conservative
33@adelatorrefoss @codesaidev
The Legacy Code
Change Algorithm
1. Identify change points.
2. Find test points.
3. Break dependencies.
4. Write tests.
5. Make changes and refactor.
34@adelatorrefoss @codesaidev
Show me the
code
8
@adelatorrefoss @codesaidev
A classic dependency
@adelatorrefoss @codesaidev
class MarsLander {
private DataBase dataBase;
MarsLander(DataBase dataBase) {
this.dataBase = dataBase;
}
void openParachute() {
Command command = new Command("open-parachute");
dataBase.save(command);
}
}
37@adelatorrefoss @codesaidev
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);
}
}
38@adelatorrefoss @codesaidev
A more complicated dependency
39@adelatorrefoss @codesaidev
class MarsRover {
void move(int x, int y) {
Command command = new Command("move", x, y);
// Connect with vehicle
SpaceVehicle vehicle = VehicleFactory.createAComplicatedOne();
vehicle.sendCommand(command);
}
}
40@adelatorrefoss @codesaidev
class MarsRover {
void move(int x, int y) {
Command command = new Command("move", x, y);
// Connect with vehicle
sendToVehicle(command);
}
protected void sendToVehicle(Command command) {
SpaceVehicle vehicle = VehicleFactory.createABigOne();
vehicle.sendCommand(command);
}
}
41@adelatorrefoss @codesaidev
class MarsRoverTest {
class MarsRoverSpy extends MarsRover {
Command commandSent;
@Override
protected void sendToVehicle(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);
}
}
42@adelatorrefoss @codesaidev
Heuristics &
Strategies
9
@adelatorrefoss @codesaidev
Clean Code
A set of rules, principles and heuristics easy to
understand by all the team.
Understandability makes change, extension and
maintenance possible.
44@adelatorrefoss @codesaidev
The 4 Rules of Simple
Design
45
Kent Beck
@adelatorrefoss @codesaidev
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)
46@adelatorrefoss @codesaidev
Hexagonal
Architecture
(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.
47@adelatorrefoss @codesaidev
class MarsRover {
void move(int x, int y) {
Command command = new Command("move", x, y);
// Connect with a communications vehicle
sendToVehicle(command);
}
protected void sendToVehicle(Command command) {
SpaceVehicle vehicle = VehicleFactory.createABigOne();
vehicle.sendCommand(command);
}
}
48@adelatorrefoss @codesaidev
Team again10
@adelatorrefoss @codesaidev
How to make the project
interesting for the teams?
The daily work with Legacy should be a challenge, an
opportunity to learn something new.
50@adelatorrefoss @codesaidev
How to learn along the way?
51
How to learn along the way?
Training in Technical skills
- Code smells, TDD, Refactoring, Design, Working with
Legacy, ...
52@adelatorrefoss @codesaidev
Knowledge Diffusion
- Pair programming
- Mob programming
- On boarding process
- Technical concerns process
How to learn along the way?
Crystallizing Knowledge
53
Changing Habits
- Meaning of Done
- Quality First Mindset
- Mentoring Through Pair Programming
- Deliberate Practice
- Have a shared team culture and a process
to change it
- Creating Critical Mass
How to learn along the way?
54
All Team Product Owning
How to learn along the way?
55
Knowledge
Diffusion
&
Crystallizing
Training in
Technical
skills
Changing Habits All Team Product
Owning
Bibliography
Working Effectively with Legacy Code. Michael C. Feathers
Refactoring. Martin Fowler
Refactoring (second ed.). Martin Fowler
56@adelatorrefoss @codesaidev
57
Preserve
your
business!
Thanks!
▸ Toño
▸ @adelatorrefoss
@adelatorrefoss @codesaidev
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
58

More Related Content

More from Antonio de la Torre Fernández

More from Antonio de la Torre Fernández (9)

¿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
 

Recently uploaded

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
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
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
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
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 is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
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
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
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
 
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
 

Recently uploaded (20)

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
 
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)
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
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
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
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 is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
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
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
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
 
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
 

20191123 CAS 2019 Legacy Code came to stay (El Legacy vino para quedarse)

  • 1. El Legacy vino para quedarse (Legacy code came to stay)Toño de la Torre @adelatorrefoss Software Crafters
  • 2.
  • 4. 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”. 4@adelatorrefoss @codesaidev
  • 5. “ To me, legacy code is simply code without tests. Michael C. Feathers 5@adelatorrefoss @codesaidev
  • 6. 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.” 6@adelatorrefoss @codesaidev
  • 7. confidence Being able to confidently make changes in any code base. 7@adelatorrefoss @codesaidev
  • 9. Code that is hard to change but still makes money @adelatorrefoss @codesaidev
  • 12. Why is it so hard for teams? @adelatorrefoss @codesaidev
  • 14. “ 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 14@adelatorrefoss @codesaidev
  • 15. retaining talent is hard in legacy projects @adelatorrefoss @codesaidev
  • 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 does code becomes so hard? 17@adelatorrefoss @codesaidev
  • 18. How to write good code? (option A) Managers or Technical Leads set a bunch of rules and/or define an architecture. It is mandatory that everyone follow these rules. Someone, usually the Tech Lead, reviews all code (via merge request) to check if everybody is following the “agreement”. 18@adelatorrefoss @codesaidev
  • 19. How to write good code? (option A) (SPOILER!) It fails 19@adelatorrefoss @codesaidev
  • 20. How to write good code? (option B) Instead let’s learn. What’s bad code? 20
  • 22. Code Smells Code structures that reflect problems on the code base. Usually indicating design flaws. A code smell can be an easy target to start improving the code. 22@adelatorrefoss @codesaidev
  • 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 @adelatorrefoss @codesaidev
  • 24. How to technically face legacy code? 6 @adelatorrefoss @codesaidev
  • 25. Reasons to change software 1. Adding a feature 2. Fixing a bug 3. Improving the design of the system 4. Optimizing resource usage Change behavior & Preserve behavior 25@adelatorrefoss @codesaidev
  • 27. Cover and Modify 1. Cover with tests first (aka regression testing) creating a safety net. Tests act as a software vise. 2. Refactor to make place (preserving behavior). 3. Make the change. 27@adelatorrefoss @codesaidev
  • 29. 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. 29@adelatorrefoss @codesaidev
  • 31. Dependency problem Much legacy code work involves breaking dependencies so that change can be easier. 7 @adelatorrefoss @codesaidev
  • 32. 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. 32@adelatorrefoss @codesaidev
  • 33. Break dependencies with conservative and safe refactorings. Being conservative means that, we might end up making the code look a little poorer in that area. Be conservative 33@adelatorrefoss @codesaidev
  • 34. The Legacy Code Change Algorithm 1. Identify change points. 2. Find test points. 3. Break dependencies. 4. Write tests. 5. Make changes and refactor. 34@adelatorrefoss @codesaidev
  • 37. class MarsLander { private DataBase dataBase; MarsLander(DataBase dataBase) { this.dataBase = dataBase; } void openParachute() { Command command = new Command("open-parachute"); dataBase.save(command); } } 37@adelatorrefoss @codesaidev
  • 38. 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); } } 38@adelatorrefoss @codesaidev
  • 39. A more complicated dependency 39@adelatorrefoss @codesaidev
  • 40. class MarsRover { void move(int x, int y) { Command command = new Command("move", x, y); // Connect with vehicle SpaceVehicle vehicle = VehicleFactory.createAComplicatedOne(); vehicle.sendCommand(command); } } 40@adelatorrefoss @codesaidev
  • 41. class MarsRover { void move(int x, int y) { Command command = new Command("move", x, y); // Connect with vehicle sendToVehicle(command); } protected void sendToVehicle(Command command) { SpaceVehicle vehicle = VehicleFactory.createABigOne(); vehicle.sendCommand(command); } } 41@adelatorrefoss @codesaidev
  • 42. class MarsRoverTest { class MarsRoverSpy extends MarsRover { Command commandSent; @Override protected void sendToVehicle(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); } } 42@adelatorrefoss @codesaidev
  • 44. Clean Code A set of rules, principles and heuristics easy to understand by all the team. Understandability makes change, extension and maintenance possible. 44@adelatorrefoss @codesaidev
  • 45. The 4 Rules of Simple Design 45 Kent Beck @adelatorrefoss @codesaidev
  • 46. 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) 46@adelatorrefoss @codesaidev
  • 47. Hexagonal Architecture (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. 47@adelatorrefoss @codesaidev
  • 48. class MarsRover { void move(int x, int y) { Command command = new Command("move", x, y); // Connect with a communications vehicle sendToVehicle(command); } protected void sendToVehicle(Command command) { SpaceVehicle vehicle = VehicleFactory.createABigOne(); vehicle.sendCommand(command); } } 48@adelatorrefoss @codesaidev
  • 50. How to make the project interesting for the teams? The daily work with Legacy should be a challenge, an opportunity to learn something new. 50@adelatorrefoss @codesaidev
  • 51. How to learn along the way? 51
  • 52. How to learn along the way? Training in Technical skills - Code smells, TDD, Refactoring, Design, Working with Legacy, ... 52@adelatorrefoss @codesaidev
  • 53. Knowledge Diffusion - Pair programming - Mob programming - On boarding process - Technical concerns process How to learn along the way? Crystallizing Knowledge 53
  • 54. Changing Habits - Meaning of Done - Quality First Mindset - Mentoring Through Pair Programming - Deliberate Practice - Have a shared team culture and a process to change it - Creating Critical Mass How to learn along the way? 54 All Team Product Owning
  • 55. How to learn along the way? 55 Knowledge Diffusion & Crystallizing Training in Technical skills Changing Habits All Team Product Owning
  • 56. Bibliography Working Effectively with Legacy Code. Michael C. Feathers Refactoring. Martin Fowler Refactoring (second ed.). Martin Fowler 56@adelatorrefoss @codesaidev
  • 58. 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 58