SlideShare a Scribd company logo
www.bnsit.pl
Natural Course of Refactoring.
A refactoring workflow.
Mariusz Sieraczkiewicz
@ms_bnsit_pl
http://msieraczkiewicz.blogspot.com
1
www.bnsit.pl
Why refactoring is like sex?
NaturalCourse of Refactoring
www.bnsit.pl
Once you get started, you’ll only stop
because you’re exhausted.
One mistake and the consequences
may be really huge.
Whyrefactoring is like sex?
NaturalCourseofRefactoring2014 3
(adaptedfrom http://www.thealmightyguru.com/Humor/Docs/ProgrammingIsLikeSex.html)
www.bnsit.pl
People more talk about it than
actually do.
You can do it for money or for fun.
It’s not really an appropriate topic for
dinner conversation.
Whyrefactoring is like sex?
NaturalCourseofRefactoring2014 4
(adaptedfrom http://www.thealmightyguru.com/Humor/Docs/ProgrammingIsLikeSex.html)
www.bnsit.pl
Beginners do a lot of noise about it.
Some people are just naturally good at it,
.. but some people will never realize how
bad they are, and you’re wasting your time
trying to tell them.
Whyrefactoring is like sex?
NaturalCourseofRefactoring2014 5
(adaptedfrom http://www.thealmightyguru.com/Humor/Docs/ProgrammingIsLikeSex.html)
www.bnsit.pl
It doesn’t go so well when you’re
drunk, but you’re more likely to do it.
You’ll miss it after a longer break.
Whyrefactoring is like sex?
NaturalCourseofRefactoring2014 6
(adaptedfrom http://www.thealmightyguru.com/Humor/Docs/ProgrammingIsLikeSex.html)
www.bnsit.pl
Code readability
NaturalCourse of Refactoring
www.bnsit.pl
.so!changesIntroDuCinG!maYBe,softwaRe,TosO,cal
LEdprOgRessIve,and.however.cHanGes!Modifies.us
uallY,sTRucTureOFmaYbe,hoWEVeRtHecoDE,And!w
HaTmaYbecumulatEdhowevEr.anD,mAkes.AnD,,and
,the.LeSs!rEAdAblE,aNd.cOdeMAybe.ANd,!and,!Th
enumber!of,sO,HoWEvErsodepeNdeNCiES,And.MA
ybeintErACtIOns!betWeenHoWevEr!differEntsySte
m.moDules!inCreasESoThat,iTsO!morE.is.diffiCuLt,T
o,AnDuNdErstandmodIFy
Why is it difficulttounderstand software aftersome timeof its evolution?
NaturalCourseofRefactoring2014 8
www.bnsit.pl
Introducing changes to software (so called
progressive changes) usually modifies
structure of the code, what cumulated
makes the code less readable. The number
of dependencies and interactions between
different system modules increase, so that
it is more difficult to understand and
modify.
Why is it difficulttounderstand software aftersome timeof its evolution?
NaturalCourseofRefactoring2014 9
www.bnsit.pl
Even answers to easy questions are difficult to
find.
The problem lies more in a code readibility,
than in the programmers reading skills.
Even great reader will not perform good in
such environment.
What alters programmersproductivity in this case?
NaturalCourseofRefactoring2014 10
www.bnsit.pl
Flavoursof refactoring
NaturalCourse of Refactoring
NaturalCourseofRefactoring2014 11
www.bnsit.pl
Twoflavours of refactoring
NaturalCourseofRefactoring2014 12
www.bnsit.pl
Everyday refactoring
Within a reach of every programmer
Can be done in minutes
Mostly safe, IDE-base automatic refactorings
For local health of the code
Part of programming practice
No excuse for not doing it
Main practices
Cleaning names
Naming conditions
Extracting methods
Moving methods and extracting classes
Everyday refactoring
NaturalCourseofRefactoring2014 13
www.bnsit.pl
Strategic refactoring
A team longer term effort
Requires aligning with iteration planning
Generates items in backlog
Risky activity that requires intensive testing (including good
tests suite)
Difficult and time-consuming
Check carefully if refactoring gives you enough value
(Feather’s Quadrant)
Main practices
Introducing high level design patterns
Introducing architectural changes
Strategic refactoring
NaturalCourseofRefactoring2014 14
www.bnsit.pl
When should I do strategic refactoring?
NaturalCourse of Refactoring
www.bnsit.pl
1. complexity := 1
2. For every decision point (if, while, for,
and, or, try, case, break, continue)
complexity++
3. if 6 <= complexity <= 10 – simplify a
method
4. if complexity > 10 – compose method
McCabe Metric (Cyclomatic Complexity)
Simplifiedversion
NaturalCourseofRefactoring2014 16
www.bnsit.pl
High complexity/
Seldom changes
Don’t touch it.
High complexity/
Frequent changes
Apply strategic
refactoring
Low complexity/
Seldom changes
Utils, good for
experiments
Low
complexity/Frequent
changes
Heaven 
Feather’sQuadrant
NaturalCourseofRefactoring2014 17
Confront with:
• team opinions
• business strategy
Frequency of changes
Complexity
www.bnsit.pl
Natural Course of Refactoring
Theprocess
www.bnsit.pl NaturalCourseofRefactoring2014 19
www.bnsit.pl
Step 0. Understandthecode
NaturalCourseofRefactoring2014 20
www.bnsit.pl
Sometimes it is the most difficult point
Try to…
• find an author and ask for help
• find somebody who worked with the code and
ask for help
• find somebody who knows the system (or
module) and ask for help
• Do it yourself if none of above are possible
Understand
NaturalCourseofRefactoring2014 21
www.bnsit.pl
Mental tools
Simple code cleaning
Clean up the names
Add temporary comments to the code
Introduce lazy variables initialization
Make optical cleanup (make more space)
Scaffolding refactoring
Do some exploratory refactoring to be thrown away
The only goal is to gain more understanding of the code
Done in Notepad or something similar
Understand
NaturalCourseofRefactoring2014 22
www.bnsit.pl
They should be temporary. Delete them after refactoring.
// SMELL it doesn’t look good, copy-
paste antipattern
// REFACTOR introduce factory
// NOTE send a message
// IDEA it can be modeled as a state
machine
Introducerefactoringcomments
NaturalCourseofRefactoring2014 23
www.bnsit.pl
Step 1. Express algorithm
NaturalCourseofRefactoring2014 24
www.bnsit.pl
Aim
Code that speaks to you
Mental tools
• Compose method
• Introduce Method Object Refactoring
• Extract method
Express algorithm
NaturalCourseofRefactoring2014 25
www.bnsit.pl
Step 2. Extractresponsibilities
NaturalCourseofRefactoring2014 26
www.bnsit.pl
Move meaningful private methods to another
classes.
You can’t test private method without hacks so
if it is worth testing, find another class where
this method will be public.
Extract responsibilities
NaturalCourseofRefactoring2014 27
www.bnsit.pl
Mental tools
Single responsibility principle
Move method refactoring
Extract class refactoring
Introduce Domain Object
Introduce Value Object
Extract responsibilities
NaturalCourseofRefactoring2014 28
www.bnsit.pl
Step 3. Introduceflexibility
NaturalCourseofRefactoring2014 29
www.bnsit.pl
Flexibility based on requirements
eg. be prepared for many cripting algorithms, starting with 5
Flexibility which emerged from code
eg. your team has written 8 reports with similar structure
Never guess for flexibility
Do you REALLY needflexibility?
NaturalCourseofRefactoring2014 30
www.bnsit.pl
Strategy, Template method – different versions
of the same algorithm
State – simple state machines
Factory – polimorphic object creation
Builder – creating complex object in multiple
steps
Decorator – flexibility in enhancing behaviour
at runtime
Observer – loosen dependencies by indirect
communication (events)
Some design patterns applications
NaturalCourseofRefactoring2014 31
www.bnsit.pl
Mental tools
S.O.L.I.D.
Design patterns
Refactoring to patterns
Apply designpatterns
NaturalCourseofRefactoring2014 32
www.bnsit.pl
Step 4. Evolve architecture
NaturalCourseofRefactoring2014 33
www.bnsit.pl
It is always a strategic decision.
It is useful to have regular Design Retrospective
meetings when such ideas are discussed.
Evolve architecture
NaturalCourseofRefactoring2014 34
www.bnsit.pl
Mental tools
Introducing/removing layers
Introducing or replacing ORM/NoSQL/?
Important change in building blocks
Changing or introducing new framework
Introducing events
Introducing state machine
Moving towords DDD, Microservices, CQRS
Introducing Bounded-Context (DDD)
Applying Anticorruption Layer
Evolve architecture
NaturalCourseofRefactoring2014 35
NaturalCourseofRefactoring2014 36
www.bnsit.pl NaturalCourseofRefactoring2014 37
Everyday refactoring
Strategic refactoring
www.bnsit.pl
It is just a model – neither true nor false
Big classes and big methods has fragments of code
in different NCR stages
Quite seldom code is in Compose method step
(which the most increases readability)
The consecutive steps are done more seldom than
preceding ones
Some comments
NaturalCourseofRefactoring2014 38
www.bnsit.pl
Extracting responsibilities and Introducing
flexibility should be attracted by current
architecture vision (Architectural Mantra)
Lack of the architecture vision may push you to
local optimum
NCR is an ongoing process and should be a part
of whole software process.
NCRand architecture
NaturalCourseofRefactoring2014 39
Technikipracyz kodem
www.bnsit.pl
Why NCR?
Easy to teach
Easy to understand and remeber
Separates everyday and strategic refactoring
Indicates the simplest (safe) possible step in the
moment
Gives hints what kind of refactorings can be
applied in the moment
NCRIN A TEAM
NaturalCourseofRefactoring2014 40
www.bnsit.pl
Natural Course of Refactoring.
A refactoring workflow.
Mariusz Sieraczkiewicz
@ms_bnsit_pl
http://msieraczkiewicz.blogspot.com
41

More Related Content

PDF
Natural course of refactoring - Mix-IT Lyon 2014
PPTX
Rokas Balevičius - Scrum meets lean
PPT
Orange Israel iPhone startAPP contest winners at MoMoTLV
PPTX
01 pp for lectur 01
PPT
Svetlana Luneva - Agile ir biurokratai: kelias į rezultatą
PDF
Matt Harasymczuk - agile@coi.gov.pl
PPS
PPTX
Viktor Kisko - Discover to deliver: agile product planning and analysis
Natural course of refactoring - Mix-IT Lyon 2014
Rokas Balevičius - Scrum meets lean
Orange Israel iPhone startAPP contest winners at MoMoTLV
01 pp for lectur 01
Svetlana Luneva - Agile ir biurokratai: kelias į rezultatą
Matt Harasymczuk - agile@coi.gov.pl
Viktor Kisko - Discover to deliver: agile product planning and analysis

Viewers also liked (19)

PPTX
Šarūnas Kasnauskas - Agile driven strategy execution
PPTX
Chris Covell and Ann-Marie Orange - Transformation from Project to Product De...
PPTX
Aleksej Kovaliov - When the Whole World is Against You
PDF
Agile Tour Montréal 2010 - The Lean within Scrum par Joe Little
PPTX
Titas Lapinskas - Technical Team Leader in Agile
PPTX
Stephen Mounsey - Performance Testing it's not that scary
PPTX
Laimonas Lileika - Hybrid Project Management: Excellence Behind a Buzzword
PDF
Dainius Mežanskas - Keeping Software Development Ecosystem Healthy
PDF
מצגת עמותת CityTLV
PDF
Lemi Orhan Ergin - Code Your Agility: Tips for Boosting Technical Agility in ...
PDF
אפריקה - סקירה כלכלית, שאולי כצנלסון
PPS
PDF
Vaidas Pilkauskas and Tadas Ščerbinskas - Can you trust your tests?
PPT
Vladimirs Ivanovs - How to create a complementary team
PDF
Jan de Vries - How to convince your boss that it is DevOps that he wants
PDF
Les essuies nouveaux sont arrivés
PPS
Israel, Posters Aeropuerto
ODP
Lyndsay Prewer - Smoothing the continuous delivery path - a tale of two teams
PDF
Scrum Gathering Cape Town - Lean vs Scrum 2013 - Pavel Dabrytski
Šarūnas Kasnauskas - Agile driven strategy execution
Chris Covell and Ann-Marie Orange - Transformation from Project to Product De...
Aleksej Kovaliov - When the Whole World is Against You
Agile Tour Montréal 2010 - The Lean within Scrum par Joe Little
Titas Lapinskas - Technical Team Leader in Agile
Stephen Mounsey - Performance Testing it's not that scary
Laimonas Lileika - Hybrid Project Management: Excellence Behind a Buzzword
Dainius Mežanskas - Keeping Software Development Ecosystem Healthy
מצגת עמותת CityTLV
Lemi Orhan Ergin - Code Your Agility: Tips for Boosting Technical Agility in ...
אפריקה - סקירה כלכלית, שאולי כצנלסון
Vaidas Pilkauskas and Tadas Ščerbinskas - Can you trust your tests?
Vladimirs Ivanovs - How to create a complementary team
Jan de Vries - How to convince your boss that it is DevOps that he wants
Les essuies nouveaux sont arrivés
Israel, Posters Aeropuerto
Lyndsay Prewer - Smoothing the continuous delivery path - a tale of two teams
Scrum Gathering Cape Town - Lean vs Scrum 2013 - Pavel Dabrytski
Ad

Similar to Mariusz Sieraczkiewicz - Natural course of refactoring (20)

PPTX
Code refactoring
PDF
Refactoring 2TheMax (con ReSharper)
PPT
Principlesinrefactoring 090906230021-phpapp01
PPTX
Refactoring workshop
PDF
Refactoring: the good, the bad and the ugly.
PDF
Code refactoring
PPTX
mehdi-refactoring.pptx
PPTX
SAD10 - Refactoring
PPTX
Refactoring
PDF
The bigrewrite
PDF
The Power Of Refactoring (4developers Krakow)
PPTX
Refactoring
PDF
Refactoring, Therapeutic Attitude to Programming.
PPT
Principles in Refactoring
PPTX
Refactoring, 2nd Edition
PPTX
Refactoring, Emergent Design & Evolutionary Architecture
PDF
Refactoring 2 The Max
PPTX
The bigrewrite
PDF
From Mess To Masterpiece - JFokus 2017
PPTX
Refactoring
Code refactoring
Refactoring 2TheMax (con ReSharper)
Principlesinrefactoring 090906230021-phpapp01
Refactoring workshop
Refactoring: the good, the bad and the ugly.
Code refactoring
mehdi-refactoring.pptx
SAD10 - Refactoring
Refactoring
The bigrewrite
The Power Of Refactoring (4developers Krakow)
Refactoring
Refactoring, Therapeutic Attitude to Programming.
Principles in Refactoring
Refactoring, 2nd Edition
Refactoring, Emergent Design & Evolutionary Architecture
Refactoring 2 The Max
The bigrewrite
From Mess To Masterpiece - JFokus 2017
Refactoring
Ad

More from Agile Lietuva (20)

PPTX
Agile Pusryčiai 2023 - „Skaitmeninė transformacija viešajame sektoriuje: nuo ...
PPTX
Agile Pusryčiai 2023 - „Kaip užsitikrinti projekto sėkmę dar iki projekto pra...
PPTX
Agile pusryčiai 2023 - „Pirštas ant projekto pulso: CPO LT Agile patirtis ir ...
PPTX
Agile Pusryčiai 2023 - „Viešasis sektorius – neatskleistas inovacijų paklauso...
PPTX
M. Kaminskas ir A. K. Remeikienė. LEAN projektas: sėkmės istorijos, iššūkiai ...
PDF
B. den Haak. How to make OKRs Lean Again
PDF
D. Aitcheson. How to make forecasts that are actually accurate.
PDF
Aleksandra Černiauskienė. Misija Bloomberg: Agile pagal amerikiečius
PDF
Maija Aniskovič. Agile įtaka komandos motyvacijai.
PDF
dr. E. Janiūnienė. Asociacijos Agile Lietuva atlikto Agile tyrimo pristatymas
PPTX
M. Aniskovič. Laužome stereotipus: Agile gali drąsiai taikyti visi
PPTX
R. Krukonis. Reikalingas greitas rezultatas – pakeiskime projekto darbų organ...
PPTX
M. Jovaišas. Viešojo sektoriaus lankstumas įgyvendinant transformacijas
PPTX
A. Kovaliov. Kas nėra Agile jaunystėje, tas neturi širdies. Kas nėra Watefall...
PDF
V. Vasiliauskas. Nestandartinis atvejis: nuo Kanban prie Scrum
PDF
Leonard Vorobej. Agile projektų valdymas pradedantiesiems
PDF
Giedrė Žemulaitytė. Agile personalo skyriaus valdyme
PDF
Gabija Fatėnaitė. Agile ir Scrum turinio kūrimo ir marketingo komandose
PPTX
Gediminas Milieška. Agile kelionės: nuo transformacijos iki planavimo dideliu...
PPT
Denis Vanpoucke. Agile kelionės:nuo transformacijos iki planavimo dideliu mastu
Agile Pusryčiai 2023 - „Skaitmeninė transformacija viešajame sektoriuje: nuo ...
Agile Pusryčiai 2023 - „Kaip užsitikrinti projekto sėkmę dar iki projekto pra...
Agile pusryčiai 2023 - „Pirštas ant projekto pulso: CPO LT Agile patirtis ir ...
Agile Pusryčiai 2023 - „Viešasis sektorius – neatskleistas inovacijų paklauso...
M. Kaminskas ir A. K. Remeikienė. LEAN projektas: sėkmės istorijos, iššūkiai ...
B. den Haak. How to make OKRs Lean Again
D. Aitcheson. How to make forecasts that are actually accurate.
Aleksandra Černiauskienė. Misija Bloomberg: Agile pagal amerikiečius
Maija Aniskovič. Agile įtaka komandos motyvacijai.
dr. E. Janiūnienė. Asociacijos Agile Lietuva atlikto Agile tyrimo pristatymas
M. Aniskovič. Laužome stereotipus: Agile gali drąsiai taikyti visi
R. Krukonis. Reikalingas greitas rezultatas – pakeiskime projekto darbų organ...
M. Jovaišas. Viešojo sektoriaus lankstumas įgyvendinant transformacijas
A. Kovaliov. Kas nėra Agile jaunystėje, tas neturi širdies. Kas nėra Watefall...
V. Vasiliauskas. Nestandartinis atvejis: nuo Kanban prie Scrum
Leonard Vorobej. Agile projektų valdymas pradedantiesiems
Giedrė Žemulaitytė. Agile personalo skyriaus valdyme
Gabija Fatėnaitė. Agile ir Scrum turinio kūrimo ir marketingo komandose
Gediminas Milieška. Agile kelionės: nuo transformacijos iki planavimo dideliu...
Denis Vanpoucke. Agile kelionės:nuo transformacijos iki planavimo dideliu mastu

Recently uploaded (20)

PDF
Salesforce Agentforce AI Implementation.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
Cost to Outsource Software Development in 2025
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Complete Guide to Website Development in Malaysia for SMEs
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PPTX
Patient Appointment Booking in Odoo with online payment
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
Download FL Studio Crack Latest version 2025 ?
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
iTop VPN Crack Latest Version Full Key 2025
Salesforce Agentforce AI Implementation.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Advanced SystemCare Ultimate Crack + Portable (2025)
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Cost to Outsource Software Development in 2025
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Complete Guide to Website Development in Malaysia for SMEs
Why Generative AI is the Future of Content, Code & Creativity?
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Patient Appointment Booking in Odoo with online payment
Oracle Fusion HCM Cloud Demo for Beginners
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Download FL Studio Crack Latest version 2025 ?
Computer Software and OS of computer science of grade 11.pptx
iTop VPN Crack Latest Version Full Key 2025

Mariusz Sieraczkiewicz - Natural course of refactoring