SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
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?

Weitere ähnliche Inhalte

Was ist angesagt?

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
Adi Bolboaca
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Samnang Chhun
 

Was ist angesagt? (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
 

Ähnlich wie Evolutionary Design - Refactoring Heuristics

Code reviews
Code reviewsCode reviews
Code reviews
Roger Xia
 
Agile_SDLC_Node.js@Paypal_ppt
Agile_SDLC_Node.js@Paypal_pptAgile_SDLC_Node.js@Paypal_ppt
Agile_SDLC_Node.js@Paypal_ppt
Hitesh Kumar
 

Ähnlich wie 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
 

Mehr von Adi Bolboaca

Coderetreat @AgileFinland Helsinki 2014 11 13
Coderetreat @AgileFinland Helsinki 2014 11 13Coderetreat @AgileFinland Helsinki 2014 11 13
Coderetreat @AgileFinland Helsinki 2014 11 13
Adi Bolboaca
 
Coderetreat @AgileFinland Tampere 2014 11 12
Coderetreat @AgileFinland Tampere 2014 11 12Coderetreat @AgileFinland Tampere 2014 11 12
Coderetreat @AgileFinland Tampere 2014 11 12
Adi 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 24
Adi 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 16
Adi Bolboaca
 
Coderetreat @Sofia 2012 10 27
Coderetreat @Sofia 2012 10 27Coderetreat @Sofia 2012 10 27
Coderetreat @Sofia 2012 10 27
Adi 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 18
Adi Bolboaca
 
Coderetreat @Vienna 2013 06 08
Coderetreat @Vienna 2013 06 08Coderetreat @Vienna 2013 06 08
Coderetreat @Vienna 2013 06 08
Adi Bolboaca
 

Mehr von 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
 

Kürzlich hochgeladen

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Kürzlich hochgeladen (20)

Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

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