SlideShare a Scribd company logo
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?

More Related Content

PDF
Basics of writing clean code
PPTX
Exceptions: Why, When, How and Where!
PPTX
Go/Ruby/Java: What's next?
PPTX
TDD & Refactoring
PDF
Writing Tests Effectively
PPTX
Competitive Programming
PPTX
Code Smells - Refactoring
PPTX
Session 3 : Competitive programming 1
Basics of writing clean code
Exceptions: Why, When, How and Where!
Go/Ruby/Java: What's next?
TDD & Refactoring
Writing Tests Effectively
Competitive Programming
Code Smells - Refactoring
Session 3 : Competitive programming 1

What's hot (20)

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

Similar to Evolutionary Design - Refactoring Heuristics (20)

PDF
Evolutionary Design - NewCrafts Paris 18 May 2018
PPS
Few minutes To better Code - Refactoring
PPTX
Refactoring workshop
PPTX
Code reviews
PDF
Approaches to teaching primary computing
PDF
Usable Software Design
ODP
What is xp
PPS
CS101- Introduction to Computing- Lecture 44
PDF
Teacher toolkit Pycon UK Sept 2018
PPTX
Clean code presentation
PPTX
Reading Notes : the practice of programming
PPTX
Code quality
PDF
Refactoring, Therapeutic Attitude to Programming.
ODP
Clean Code - Part 2
PPTX
Agile_SDLC_Node.js@Paypal_ppt
PDF
What would Jesus Developer do?
PPTX
Practices of agile developers
PDF
It's XP, Stupid
PPTX
Eurosport's Kodakademi #2
PDF
Code refactoring workshop (in Javascript)
Evolutionary Design - NewCrafts Paris 18 May 2018
Few minutes To better Code - Refactoring
Refactoring workshop
Code reviews
Approaches to teaching primary computing
Usable Software Design
What is xp
CS101- Introduction to Computing- Lecture 44
Teacher toolkit Pycon UK Sept 2018
Clean code presentation
Reading Notes : the practice of programming
Code quality
Refactoring, Therapeutic Attitude to Programming.
Clean Code - Part 2
Agile_SDLC_Node.js@Paypal_ppt
What would Jesus Developer do?
Practices of agile developers
It's XP, Stupid
Eurosport's Kodakademi #2
Code refactoring workshop (in Javascript)
Ad

More from Adi Bolboaca (19)

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

Recently uploaded (20)

PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Introduction to Artificial Intelligence
PPTX
Essential Infomation Tech presentation.pptx
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
System and Network Administration Chapter 2
PDF
medical staffing services at VALiNTRY
PPTX
Transform Your Business with a Software ERP System
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
System and Network Administraation Chapter 3
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
Reimagine Home Health with the Power of Agentic AI​
Odoo Companies in India – Driving Business Transformation.pdf
CHAPTER 2 - PM Management and IT Context
Introduction to Artificial Intelligence
Essential Infomation Tech presentation.pptx
Upgrade and Innovation Strategies for SAP ERP Customers
Softaken Excel to vCard Converter Software.pdf
System and Network Administration Chapter 2
medical staffing services at VALiNTRY
Transform Your Business with a Software ERP System
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Design an Analysis of Algorithms II-SECS-1021-03
System and Network Administraation Chapter 3
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
How to Choose the Right IT Partner for Your Business in Malaysia
Design an Analysis of Algorithms I-SECS-1021-03
2025 Textile ERP Trends: SAP, Odoo & Oracle
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
VVF-Customer-Presentation2025-Ver1.9.pptx

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