SlideShare una empresa de Scribd logo
1 de 23
Descargar para leer sin conexión
Evolutionary Design
- Refactoring Heuristics -
By Adrian Bolboacă
blog.adrianbolboaca.ro
Programmer, Trainer, Coach
Focused on organizational and
technical coaching
Co-Author of the Coderetreat Book
leanpub.com/coderetreat
Interested in raising the bar of
software development
Experimenting with Evolutionary
Design for ~6 year
How do we evolve the code?
Focused on solution
● Plan, Write, Deploy (waterfall)
● Planned & Iterative (misunderstood Agile)
● Planned & Iterative & Incorporate feedback (Scrum)
Focused on problem
● Unplanned & Iterative (misunderstood extreme programming)
● Unplanned & Iterative & Incorporate feedback
(evolutionary)
Code
Evolution
Focused
On
solution
Code Evolution: Focused on solution
1. Analyze
2. Find at least three solutions
3. Choose the best solution
4. Implement the chosen solution
a. Implement a feature
b. Improve feature
c. Implement next feature
d. Refactor
e. ….
5. Measure solution efficiency
6. Improve the implementation
7. Done
Code
Evolution
Focused
On
problem
Code Evolution: focused on problem
1. Analyze
2. Understand the problem
3. Find the simplest solution possible
4. Implement the simplest solution possible (start with a
test)
5. Complicate solution to be closer to reality (add more
tests)
6. When duplication occurs, extract design elements
7. When solution is good enough, stop
8. Check, Test and Deploy
Refactoring
● Essential in evolutionary design
“Refactoring means changing the structure of the code
without changing its external observable behavior”
● Purpose: generate design specific for the problem
● How: Navigate through possible solutions
● Prerequisites:
○ Know design concepts and “laws”
○ Observe violations of design concepts
○ A lot of practice
Refactorings
● Are specific
● Have clear steps
● Some of them are automated by tools
● When used in correct order they generate flow
● Often not used in correct order
Problem: When do I know how to use a specific refactoring
technique?
Solution: Refactoring Heuristics
Refactoring
Heuristics
Refactoring heuristics
● Signs telling you when to use a refactoring
● Are educated by practice
● Useful not to get stuck in refactoring
● Useful understanding when you used the wrong refactoring
● Help you avoid mistakes
● Can get you in a refactoring flow
1. Refactoring mantra
1. Write / Execute simplest test
2. (Write the simplest production code to make the test
pass)
3. Refactor
a. Are names good enough? (variables, methods, classes, etc)
b. Is the structure right (coupling, cohesion, responsibilities, etc)
c. Am I going on a good path?
4. Commit to local source control
5. Go to 1
After ~25 minutes take a break
Maybe push to central source control repository
2. The rule of three
“Whenever I see a design element repeat itself at least
three times, it might be a sign of duplication”
Solution:
1. Make duplication identical
2. Use extract refactoring (constant, variable, method,
class)
3. Restructure code to look nice
Hint: Always create duplication in order to remove it
3. Unnatural third party
“When code throughout the system is not respecting its
natural level of abstraction and will cross one or more
architectural boundaries (e.g. layers) of the system”
Solution:
1. Extract the code blocks to methods
2. Move the extracted methods to a new module raising the
abstraction of the system and encapsulating the 3rd party
3. Check if the code structure is correct
4. If I have a vampire structure, remove it
4. Keep Small visual distance
“Whenever refactoring, keep the similar pieces of code close
one to another in order to spot duplication”
Solution:
● Use your IDE to move the similar methods
OR
● Copy / paste the method, then delete the initial method
5. Small code width
“When the code line is too wide it is difficult to
understand”
● Change the font size in your IDE to 18. If you cannot see
all the code in the screen, the code is too wide.
Solutions:
● Extract method
● Consolidate conditional
● Consolidate logical expression
6. Adult parameter
“Many methods have the same parameter in the same class”
● Typically happens when we extract pure functions from a
bigger code base
Solution:
1. Create a class field for that parameter
2. Change signature of each method to remove that parameter
3. Check, Test & Commit
More Refactoring Heuristics
● Vampire Class
● Extract only Domain Concepts
● Close the Closure
● Zombie Class
● Redundant Comment
● Always rename one entity at a time
● … and many more
Soon read more about them on blog.adrianbolboaca.ro
Refactoring, TDD & Structural Brain Changes
Maguire et al. 2000
“The role of the hippocampus is to facilitate spatial
memory, in the form of navigation”
“A correlation was found between the amount of time spent as
a taxi driver and volume in the right posterior hippocampus”
“The results provide evidence [..] that extensive practice
with spatial navigation affects the hippocampus”
https://www.tutor2u.net/psychology/reference/maguire-2000
So i leave you with one idea
Wire your brain by practicing
refactoring if you want to be able
to navigate to the best solutions.
Start with Refactoring Heuristics.
Let’s Pair
I am available for face 2 face or remote pairing
Just drop a line http://blog.adrianbolboaca.ro/contact
Questions?

Más contenido relacionado

La actualidad más candente

Lập trình hướng kiểm thử - Test Driven development
Lập trình hướng kiểm thử - Test Driven developmentLập trình hướng kiểm thử - Test Driven development
Lập trình hướng kiểm thử - Test Driven developmentAnh Lê
 
How to deliver the right software (Specification by example)
How to deliver the right software (Specification by example)How to deliver the right software (Specification by example)
How to deliver the right software (Specification by example)Asier Barrenetxea
 
Key learnings from my refactor journey.
Key learnings from my refactor journey.Key learnings from my refactor journey.
Key learnings from my refactor journey.Thiago Dos Santos Hora
 
Writing clean scientific software Murphy cleancoding
Writing clean scientific software Murphy cleancodingWriting clean scientific software Murphy cleancoding
Writing clean scientific software Murphy cleancodingsaber tabatabaee
 
Basic software engineering principles with code examples - Session 2
Basic software engineering principles with code examples - Session 2Basic software engineering principles with code examples - Session 2
Basic software engineering principles with code examples - Session 2LahiruWijewardana1
 
Effective Unit Testing
Effective Unit TestingEffective Unit Testing
Effective Unit TestingEyal Kenig
 
Basic software engineering principles - Session 1
Basic software engineering principles - Session 1Basic software engineering principles - Session 1
Basic software engineering principles - Session 1LahiruWijewardana1
 
Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013
Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013
Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013Adi Bolboaca
 
Road map to competitive programming
Road map to competitive programmingRoad map to competitive programming
Road map to competitive programmingTutort Academy
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentSamnang Chhun
 
Training methdology testers to developers
Training methdology   testers to developersTraining methdology   testers to developers
Training methdology testers to developersGurumurthy Ramamurthy
 
Pragmatic Programmer
Pragmatic ProgrammerPragmatic Programmer
Pragmatic ProgrammerBert Añasco
 
An introduction to Competitive Programming
An introduction to Competitive ProgrammingAn introduction to Competitive Programming
An introduction to Competitive ProgrammingGaurav Agarwal
 
Workshop on programming contest
Workshop on programming contestWorkshop on programming contest
Workshop on programming contestAbir Khan
 
Code Review Matters and Manners
Code Review Matters and MannersCode Review Matters and Manners
Code Review Matters and MannersTrisha Gee
 
The pragmatic programmer
The pragmatic programmerThe pragmatic programmer
The pragmatic programmerNilesh Sharma
 
Programming the Programmer
Programming the ProgrammerProgramming the Programmer
Programming the Programmervipinkumar_n
 

La actualidad más candente (20)

Lập trình hướng kiểm thử - Test Driven development
Lập trình hướng kiểm thử - Test Driven developmentLập trình hướng kiểm thử - Test Driven development
Lập trình hướng kiểm thử - Test Driven development
 
How to deliver the right software (Specification by example)
How to deliver the right software (Specification by example)How to deliver the right software (Specification by example)
How to deliver the right software (Specification by example)
 
Key learnings from my refactor journey.
Key learnings from my refactor journey.Key learnings from my refactor journey.
Key learnings from my refactor journey.
 
Writing clean scientific software Murphy cleancoding
Writing clean scientific software Murphy cleancodingWriting clean scientific software Murphy cleancoding
Writing clean scientific software Murphy cleancoding
 
Basic software engineering principles with code examples - Session 2
Basic software engineering principles with code examples - Session 2Basic software engineering principles with code examples - Session 2
Basic software engineering principles with code examples - Session 2
 
Effective Unit Testing
Effective Unit TestingEffective Unit Testing
Effective Unit Testing
 
Basic software engineering principles - Session 1
Basic software engineering principles - Session 1Basic software engineering principles - Session 1
Basic software engineering principles - Session 1
 
Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013
Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013
Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013
 
clean code - uncle bob
clean code - uncle bobclean code - uncle bob
clean code - uncle bob
 
TDD with RSpec
TDD with RSpecTDD with RSpec
TDD with RSpec
 
Object Calisthenics in Objective-C
Object Calisthenics in Objective-CObject Calisthenics in Objective-C
Object Calisthenics in Objective-C
 
Road map to competitive programming
Road map to competitive programmingRoad map to competitive programming
Road map to competitive programming
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Training methdology testers to developers
Training methdology   testers to developersTraining methdology   testers to developers
Training methdology testers to developers
 
Pragmatic Programmer
Pragmatic ProgrammerPragmatic Programmer
Pragmatic Programmer
 
An introduction to Competitive Programming
An introduction to Competitive ProgrammingAn introduction to Competitive Programming
An introduction to Competitive Programming
 
Workshop on programming contest
Workshop on programming contestWorkshop on programming contest
Workshop on programming contest
 
Code Review Matters and Manners
Code Review Matters and MannersCode Review Matters and Manners
Code Review Matters and Manners
 
The pragmatic programmer
The pragmatic programmerThe pragmatic programmer
The pragmatic programmer
 
Programming the Programmer
Programming the ProgrammerProgramming the Programmer
Programming the Programmer
 

Similar a Evolutionary Design - Refactoring Heuristics

Evolutionary Design - NewCrafts Paris 18 May 2018
Evolutionary Design - NewCrafts Paris 18 May 2018Evolutionary Design - NewCrafts Paris 18 May 2018
Evolutionary Design - NewCrafts Paris 18 May 2018Adi Bolboaca
 
Few minutes To better Code - Refactoring
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - RefactoringDiaa Al-Salehi
 
Refactoring workshop
Refactoring workshop Refactoring workshop
Refactoring workshop Itzik Saban
 
Code reviews
Code reviewsCode reviews
Code reviewsRoger Xia
 
Approaches to teaching primary computing
Approaches to teaching primary computingApproaches to teaching primary computing
Approaches to teaching primary computingJEcomputing
 
CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44Bilal Ahmed
 
Teacher toolkit Pycon UK Sept 2018
Teacher toolkit Pycon UK Sept 2018Teacher toolkit Pycon UK Sept 2018
Teacher toolkit Pycon UK Sept 2018Sue Sentance
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentationBhavin Gandhi
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programmingJuggernaut Liu
 
Refactoring, Therapeutic Attitude to Programming.
Refactoring, Therapeutic Attitude to Programming.Refactoring, Therapeutic Attitude to Programming.
Refactoring, Therapeutic Attitude to Programming.Amin Shahnazari
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2Knoldus Inc.
 
Agile_SDLC_Node.js@Paypal_ppt
Agile_SDLC_Node.js@Paypal_pptAgile_SDLC_Node.js@Paypal_ppt
Agile_SDLC_Node.js@Paypal_pptHitesh Kumar
 
What would Jesus Developer do?
What would Jesus Developer do?What would Jesus Developer do?
What would Jesus Developer do?Lukáš Čech
 
Practices of agile developers
Practices of agile developersPractices of agile developers
Practices of agile developersDUONG Trong Tan
 

Similar a Evolutionary Design - Refactoring Heuristics (20)

Evolutionary Design - NewCrafts Paris 18 May 2018
Evolutionary Design - NewCrafts Paris 18 May 2018Evolutionary Design - NewCrafts Paris 18 May 2018
Evolutionary Design - NewCrafts Paris 18 May 2018
 
Lecture 24
Lecture 24Lecture 24
Lecture 24
 
Few minutes To better Code - Refactoring
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - Refactoring
 
Refactoring workshop
Refactoring workshop Refactoring workshop
Refactoring workshop
 
Code reviews
Code reviewsCode reviews
Code reviews
 
Approaches to teaching primary computing
Approaches to teaching primary computingApproaches to teaching primary computing
Approaches to teaching primary computing
 
Usable Software Design
Usable Software DesignUsable Software Design
Usable Software Design
 
What is xp
What is xpWhat is xp
What is xp
 
CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44
 
Teacher toolkit Pycon UK Sept 2018
Teacher toolkit Pycon UK Sept 2018Teacher toolkit Pycon UK Sept 2018
Teacher toolkit Pycon UK Sept 2018
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
Reading Notes : the practice of programming
Reading Notes : the practice of programmingReading Notes : the practice of programming
Reading Notes : the practice of programming
 
Code quality
Code quality Code quality
Code quality
 
Refactoring, Therapeutic Attitude to Programming.
Refactoring, Therapeutic Attitude to Programming.Refactoring, Therapeutic Attitude to Programming.
Refactoring, Therapeutic Attitude to Programming.
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
 
Agile_SDLC_Node.js@Paypal_ppt
Agile_SDLC_Node.js@Paypal_pptAgile_SDLC_Node.js@Paypal_ppt
Agile_SDLC_Node.js@Paypal_ppt
 
What would Jesus Developer do?
What would Jesus Developer do?What would Jesus Developer do?
What would Jesus Developer do?
 
Practices of agile developers
Practices of agile developersPractices of agile developers
Practices of agile developers
 
It's XP, Stupid
It's XP, StupidIt's XP, Stupid
It's XP, Stupid
 
Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
 

Más de Adi Bolboaca

Stop Task Switching
Stop Task SwitchingStop Task Switching
Stop Task SwitchingAdi Bolboaca
 
Evolutionary Design: Take Only One Decision at a Time
Evolutionary Design: Take Only One Decision at a TimeEvolutionary Design: Take Only One Decision at a Time
Evolutionary Design: Take Only One Decision at a TimeAdi Bolboaca
 
Behind Agile Practices
Behind Agile PracticesBehind Agile Practices
Behind Agile PracticesAdi Bolboaca
 
Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015
Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015
Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015Adi Bolboaca
 
Coderetreat @AgileFinland Turku 2014 11 15
 Coderetreat @AgileFinland Turku 2014 11 15 Coderetreat @AgileFinland Turku 2014 11 15
Coderetreat @AgileFinland Turku 2014 11 15Adi Bolboaca
 
Coderetreat @AgileFinland Helsinki 2014 11 13
Coderetreat @AgileFinland Helsinki 2014 11 13Coderetreat @AgileFinland Helsinki 2014 11 13
Coderetreat @AgileFinland Helsinki 2014 11 13Adi Bolboaca
 
Coderetreat @AgileFinland Tampere 2014 11 12
Coderetreat @AgileFinland Tampere 2014 11 12Coderetreat @AgileFinland Tampere 2014 11 12
Coderetreat @AgileFinland Tampere 2014 11 12Adi Bolboaca
 
Refactoring Dojo @AgileWorks Bucharest 21 May 2014
Refactoring Dojo @AgileWorks Bucharest 21 May 2014Refactoring Dojo @AgileWorks Bucharest 21 May 2014
Refactoring Dojo @AgileWorks Bucharest 21 May 2014Adi Bolboaca
 
Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15
Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15
Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15Adi Bolboaca
 
TDD Mini Workshop @ Bucharest JUG 2014 04 24
TDD Mini Workshop @ Bucharest JUG 2014 04 24TDD Mini Workshop @ Bucharest JUG 2014 04 24
TDD Mini Workshop @ Bucharest JUG 2014 04 24Adi Bolboaca
 
Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21
Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21
Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21Adi Bolboaca
 
Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13
Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13
Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13Adi Bolboaca
 
Code retreat @AgileWorks Bucharest 7 September 2013
Code retreat @AgileWorks Bucharest 7 September 2013Code retreat @AgileWorks Bucharest 7 September 2013
Code retreat @AgileWorks Bucharest 7 September 2013Adi Bolboaca
 
Coderetreat @AgileWorks Bucharest 2012 07 06
Coderetreat @AgileWorks Bucharest 2012 07 06 Coderetreat @AgileWorks Bucharest 2012 07 06
Coderetreat @AgileWorks Bucharest 2012 07 06 Adi Bolboaca
 
Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16Adi Bolboaca
 
Coderetreat @Sofia 2012 10 27
Coderetreat @Sofia 2012 10 27Coderetreat @Sofia 2012 10 27
Coderetreat @Sofia 2012 10 27Adi Bolboaca
 
Coderetreat @Turku 2012 10 20
Coderetreat @Turku 2012 10 20 Coderetreat @Turku 2012 10 20
Coderetreat @Turku 2012 10 20 Adi Bolboaca
 
Coderetreat @Sibiu 2012 08 18
Coderetreat @Sibiu 2012 08 18Coderetreat @Sibiu 2012 08 18
Coderetreat @Sibiu 2012 08 18Adi Bolboaca
 
Coderetreat @Vienna 2013 06 08
Coderetreat @Vienna 2013 06 08Coderetreat @Vienna 2013 06 08
Coderetreat @Vienna 2013 06 08Adi Bolboaca
 

Más de Adi Bolboaca (19)

Stop Task Switching
Stop Task SwitchingStop Task Switching
Stop Task Switching
 
Evolutionary Design: Take Only One Decision at a Time
Evolutionary Design: Take Only One Decision at a TimeEvolutionary Design: Take Only One Decision at a Time
Evolutionary Design: Take Only One Decision at a Time
 
Behind Agile Practices
Behind Agile PracticesBehind Agile Practices
Behind Agile Practices
 
Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015
Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015
Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015
 
Coderetreat @AgileFinland Turku 2014 11 15
 Coderetreat @AgileFinland Turku 2014 11 15 Coderetreat @AgileFinland Turku 2014 11 15
Coderetreat @AgileFinland Turku 2014 11 15
 
Coderetreat @AgileFinland Helsinki 2014 11 13
Coderetreat @AgileFinland Helsinki 2014 11 13Coderetreat @AgileFinland Helsinki 2014 11 13
Coderetreat @AgileFinland Helsinki 2014 11 13
 
Coderetreat @AgileFinland Tampere 2014 11 12
Coderetreat @AgileFinland Tampere 2014 11 12Coderetreat @AgileFinland Tampere 2014 11 12
Coderetreat @AgileFinland Tampere 2014 11 12
 
Refactoring Dojo @AgileWorks Bucharest 21 May 2014
Refactoring Dojo @AgileWorks Bucharest 21 May 2014Refactoring Dojo @AgileWorks Bucharest 21 May 2014
Refactoring Dojo @AgileWorks Bucharest 21 May 2014
 
Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15
Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15
Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15
 
TDD Mini Workshop @ Bucharest JUG 2014 04 24
TDD Mini Workshop @ Bucharest JUG 2014 04 24TDD Mini Workshop @ Bucharest JUG 2014 04 24
TDD Mini Workshop @ Bucharest JUG 2014 04 24
 
Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21
Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21
Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21
 
Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13
Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13
Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13
 
Code retreat @AgileWorks Bucharest 7 September 2013
Code retreat @AgileWorks Bucharest 7 September 2013Code retreat @AgileWorks Bucharest 7 September 2013
Code retreat @AgileWorks Bucharest 7 September 2013
 
Coderetreat @AgileWorks Bucharest 2012 07 06
Coderetreat @AgileWorks Bucharest 2012 07 06 Coderetreat @AgileWorks Bucharest 2012 07 06
Coderetreat @AgileWorks Bucharest 2012 07 06
 
Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16
 
Coderetreat @Sofia 2012 10 27
Coderetreat @Sofia 2012 10 27Coderetreat @Sofia 2012 10 27
Coderetreat @Sofia 2012 10 27
 
Coderetreat @Turku 2012 10 20
Coderetreat @Turku 2012 10 20 Coderetreat @Turku 2012 10 20
Coderetreat @Turku 2012 10 20
 
Coderetreat @Sibiu 2012 08 18
Coderetreat @Sibiu 2012 08 18Coderetreat @Sibiu 2012 08 18
Coderetreat @Sibiu 2012 08 18
 
Coderetreat @Vienna 2013 06 08
Coderetreat @Vienna 2013 06 08Coderetreat @Vienna 2013 06 08
Coderetreat @Vienna 2013 06 08
 

Último

Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Anthony Dahanne
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
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
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
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
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 

Último (20)

Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
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
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
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
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 

Evolutionary Design - Refactoring Heuristics

  • 1. Evolutionary Design - Refactoring Heuristics - By Adrian Bolboacă
  • 2. blog.adrianbolboaca.ro Programmer, Trainer, Coach Focused on organizational and technical coaching Co-Author of the Coderetreat Book leanpub.com/coderetreat Interested in raising the bar of software development Experimenting with Evolutionary Design for ~6 year
  • 3. How do we evolve the code? Focused on solution ● Plan, Write, Deploy (waterfall) ● Planned & Iterative (misunderstood Agile) ● Planned & Iterative & Incorporate feedback (Scrum) Focused on problem ● Unplanned & Iterative (misunderstood extreme programming) ● Unplanned & Iterative & Incorporate feedback (evolutionary)
  • 5. Code Evolution: Focused on solution 1. Analyze 2. Find at least three solutions 3. Choose the best solution 4. Implement the chosen solution a. Implement a feature b. Improve feature c. Implement next feature d. Refactor e. …. 5. Measure solution efficiency 6. Improve the implementation 7. Done
  • 7. Code Evolution: focused on problem 1. Analyze 2. Understand the problem 3. Find the simplest solution possible 4. Implement the simplest solution possible (start with a test) 5. Complicate solution to be closer to reality (add more tests) 6. When duplication occurs, extract design elements 7. When solution is good enough, stop 8. Check, Test and Deploy
  • 8. Refactoring ● Essential in evolutionary design “Refactoring means changing the structure of the code without changing its external observable behavior” ● Purpose: generate design specific for the problem ● How: Navigate through possible solutions ● Prerequisites: ○ Know design concepts and “laws” ○ Observe violations of design concepts ○ A lot of practice
  • 9. Refactorings ● Are specific ● Have clear steps ● Some of them are automated by tools ● When used in correct order they generate flow ● Often not used in correct order Problem: When do I know how to use a specific refactoring technique? Solution: Refactoring Heuristics
  • 11. Refactoring heuristics ● Signs telling you when to use a refactoring ● Are educated by practice ● Useful not to get stuck in refactoring ● Useful understanding when you used the wrong refactoring ● Help you avoid mistakes ● Can get you in a refactoring flow
  • 12. 1. Refactoring mantra 1. Write / Execute simplest test 2. (Write the simplest production code to make the test pass) 3. Refactor a. Are names good enough? (variables, methods, classes, etc) b. Is the structure right (coupling, cohesion, responsibilities, etc) c. Am I going on a good path? 4. Commit to local source control 5. Go to 1 After ~25 minutes take a break Maybe push to central source control repository
  • 13. 2. The rule of three “Whenever I see a design element repeat itself at least three times, it might be a sign of duplication” Solution: 1. Make duplication identical 2. Use extract refactoring (constant, variable, method, class) 3. Restructure code to look nice Hint: Always create duplication in order to remove it
  • 14. 3. Unnatural third party “When code throughout the system is not respecting its natural level of abstraction and will cross one or more architectural boundaries (e.g. layers) of the system” Solution: 1. Extract the code blocks to methods 2. Move the extracted methods to a new module raising the abstraction of the system and encapsulating the 3rd party 3. Check if the code structure is correct 4. If I have a vampire structure, remove it
  • 15. 4. Keep Small visual distance “Whenever refactoring, keep the similar pieces of code close one to another in order to spot duplication” Solution: ● Use your IDE to move the similar methods OR ● Copy / paste the method, then delete the initial method
  • 16. 5. Small code width “When the code line is too wide it is difficult to understand” ● Change the font size in your IDE to 18. If you cannot see all the code in the screen, the code is too wide. Solutions: ● Extract method ● Consolidate conditional ● Consolidate logical expression
  • 17. 6. Adult parameter “Many methods have the same parameter in the same class” ● Typically happens when we extract pure functions from a bigger code base Solution: 1. Create a class field for that parameter 2. Change signature of each method to remove that parameter 3. Check, Test & Commit
  • 18. More Refactoring Heuristics ● Vampire Class ● Extract only Domain Concepts ● Close the Closure ● Zombie Class ● Redundant Comment ● Always rename one entity at a time ● … and many more Soon read more about them on blog.adrianbolboaca.ro
  • 19. Refactoring, TDD & Structural Brain Changes
  • 20. Maguire et al. 2000 “The role of the hippocampus is to facilitate spatial memory, in the form of navigation” “A correlation was found between the amount of time spent as a taxi driver and volume in the right posterior hippocampus” “The results provide evidence [..] that extensive practice with spatial navigation affects the hippocampus” https://www.tutor2u.net/psychology/reference/maguire-2000
  • 21. So i leave you with one idea Wire your brain by practicing refactoring if you want to be able to navigate to the best solutions. Start with Refactoring Heuristics.
  • 22. Let’s Pair I am available for face 2 face or remote pairing Just drop a line http://blog.adrianbolboaca.ro/contact