SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
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?
Natural Course 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.
Why refactoring is like sex?
Natural Course of Refactoring 2014 3
(adapted from 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.
Why refactoring is like sex?
Natural Course of Refactoring 2014 4
(adapted from 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.
Why refactoring is like sex?
Natural Course of Refactoring 2014 5
(adapted from 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.
Why refactoring is like sex?
Natural Course of Refactoring 2014 6
(adapted from http://www.thealmightyguru.com/Humor/Docs/ProgrammingIsLikeSex.html)
www.bnsit.pl
Code readability
Natural Course of Refactoring
www.bnsit.pl
.so!changesIntroDuCinG!maYBe,softwaRe,TosO,
calLEdprOgRessIve,and.however.cHanGes!Modi
fies.usuallY,sTRucTureOFmaYbe,hoWEVeRtHeco
DE,And!wHaTmaYbecumulatEdhowevEr.anD,m
Akes.AnD,,and,the.LeSs!rEAdAblE,aNd.cOdeMA
ybe.ANd,!and,!Thenumber!of,sO,HoWEvErsode
peNdeNCiES,And.MAybeintErACtIOns!betWeen
HoWevEr!differEntsyStem.moDules!inCreasESo
That,iTsO!morE.is.diffiCuLt,To,AnDuNdErstandm
odIFy
Why is it difficult to understand software after some
time of its evolution?
Natural Course of Refactoring 2014 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 difficult to understand software after some
time of its evolution?
Natural Course of Refactoring 2014 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 programmers productivity in this case?
Natural Course of Refactoring 2014 10
www.bnsit.pl
Flavours of refactoring
Natural Course of Refactoring
Natural Course of Refactoring 2014 11
www.bnsit.pl
Two flavours of refactoring
Natural Course of Refactoring 2014 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
Natural Course of Refactoring 2014 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
Natural Course of Refactoring 2014 14
www.bnsit.pl
When should I do strategic refactoring?
Natural Course 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)
Simplified version
Natural Course of Refactoring 2014 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’s Quadrant
Natural Course of Refactoring 2014 17
Confront with:
• team opinions
• business strategy
Frequency of changes
Complexity
www.bnsit.pl
Natural Course of Refactoring
The process
www.bnsit.pl Natural Course of Refactoring 2014 19
www.bnsit.pl
Step 0. Understand the code
Natural Course of Refactoring 2014 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
Natural Course of Refactoring 2014 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
Natural Course of Refactoring 2014 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
Introduce refactoring comments
Natural Course of Refactoring 2014 23
www.bnsit.pl
Step 1. Express algorithm
Natural Course of Refactoring 2014 24
www.bnsit.pl
Aim
Code that speaks to you
Mental tools
• Compose method
• Introduce Method Object Refactoring
• Extract method
Express algorithm
Natural Course of Refactoring 2014 25
www.bnsit.pl
Step 2. Extract responsibilities
Natural Course of Refactoring 2014 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
Natural Course of Refactoring 2014 27
www.bnsit.pl
Mental tools
Single responsibility principle
Move method refactoring
Extract class refactoring
Introduce Domain Object
Introduce Value Object
Extract responsibilities
Natural Course of Refactoring 2014 28
www.bnsit.pl
Step 3. Introduce flexibility
Natural Course of Refactoring 2014 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 need flexibility?
Natural Course of Refactoring 2014 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
Natural Course of Refactoring 2014 31
www.bnsit.pl
Mental tools
S.O.L.I.D.
Design patterns
Refactoring to patterns
Apply design patterns
Natural Course of Refactoring 2014 32
www.bnsit.pl
Step 4. Evolve architecture
Natural Course of Refactoring 2014 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
Natural Course of Refactoring 2014 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
Natural Course of Refactoring 2014 35
Natural Course of Refactoring 2014 36
www.bnsit.pl Natural Course of Refactoring 2014 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
Natural Course of Refactoring 2014 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.
NCR and architecture
Natural Course of Refactoring 2014 39
Techniki pracy z 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
NCR IN A TEAM
Natural Course of Refactoring 2014 40
www.bnsit.pl
Natural Course of Refactoring.
A refactoring workflow.
Mariusz Sieraczkiewicz
@ms_bnsit_pl
http://msieraczkiewicz.blogspot.com
41

Contenu connexe

Similaire à Why refactoring is like sex? Natural Course of Refactoring workflow

10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)guestebde
 
Agile Development in .NET
Agile Development in .NETAgile Development in .NET
Agile Development in .NETdanhermes
 
high performance mysql
high performance mysqlhigh performance mysql
high performance mysqlliufabin 66688
 
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
 
Dev Ops for systems of record - Talk at Agile Australia 2015
Dev Ops for systems of record - Talk at Agile Australia 2015Dev Ops for systems of record - Talk at Agile Australia 2015
Dev Ops for systems of record - Talk at Agile Australia 2015Mirco Hering
 
Quality Built In @ Spotify
Quality Built In @ SpotifyQuality Built In @ Spotify
Quality Built In @ SpotifyAndrii Dzynia
 
Workshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfWorkshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfTobiasGoeschel
 
Passing The Joel Test In The PHP World
Passing The Joel Test In The PHP WorldPassing The Joel Test In The PHP World
Passing The Joel Test In The PHP WorldLorna Mitchell
 
Become a better UX designer through code
Become a better UX designer through codeBecome a better UX designer through code
Become a better UX designer through codeRamon Lapenta
 
Managing Creativity
Managing CreativityManaging Creativity
Managing Creativitykamaelian
 
Contributing to Drupal
Contributing to DrupalContributing to Drupal
Contributing to DrupalChris Skene
 
The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)Stefan Koopmanschap
 
CodeValue Architecture Next 2018 - Executive track dilemmas and solutions in...
CodeValue Architecture Next 2018 - Executive track  dilemmas and solutions in...CodeValue Architecture Next 2018 - Executive track  dilemmas and solutions in...
CodeValue Architecture Next 2018 - Executive track dilemmas and solutions in...Erez PEDRO
 
Case Study: Experiences Using IBM Rational Method Composer to Deliver a BPM I...
Case Study: Experiences Using IBM Rational Method Composer to Deliver a BPM I...Case Study: Experiences Using IBM Rational Method Composer to Deliver a BPM I...
Case Study: Experiences Using IBM Rational Method Composer to Deliver a BPM I...ghodgkinson
 
Deploy, manage, and customize with SharePoint Patterns and Practices tools an...
Deploy, manage, and customize with SharePoint Patterns and Practices tools an...Deploy, manage, and customize with SharePoint Patterns and Practices tools an...
Deploy, manage, and customize with SharePoint Patterns and Practices tools an...SharePoint Patterns and Practices
 
BA and Beyond 20 - Elke Steegmans and David Vandenbroeck - Behaviour-driven d...
BA and Beyond 20 - Elke Steegmans and David Vandenbroeck - Behaviour-driven d...BA and Beyond 20 - Elke Steegmans and David Vandenbroeck - Behaviour-driven d...
BA and Beyond 20 - Elke Steegmans and David Vandenbroeck - Behaviour-driven d...BA and Beyond
 
Agile Methodologies And Extreme Programming - Svetlin Nakov
Agile Methodologies And Extreme Programming - Svetlin NakovAgile Methodologies And Extreme Programming - Svetlin Nakov
Agile Methodologies And Extreme Programming - Svetlin NakovSvetlin Nakov
 
Software System Engineering - Chapter 2
Software System Engineering - Chapter 2Software System Engineering - Chapter 2
Software System Engineering - Chapter 2Fadhil Ismail
 
WDS trainer presentation - MLOps.pptx
WDS trainer presentation - MLOps.pptxWDS trainer presentation - MLOps.pptx
WDS trainer presentation - MLOps.pptxArthur240715
 
Refactoring, Therapeutic Attitude to Programming.
Refactoring, Therapeutic Attitude to Programming.Refactoring, Therapeutic Attitude to Programming.
Refactoring, Therapeutic Attitude to Programming.Amin Shahnazari
 

Similaire à Why refactoring is like sex? Natural Course of Refactoring workflow (20)

10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)
 
Agile Development in .NET
Agile Development in .NETAgile Development in .NET
Agile Development in .NET
 
high performance mysql
high performance mysqlhigh performance mysql
high performance mysql
 
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
 
Dev Ops for systems of record - Talk at Agile Australia 2015
Dev Ops for systems of record - Talk at Agile Australia 2015Dev Ops for systems of record - Talk at Agile Australia 2015
Dev Ops for systems of record - Talk at Agile Australia 2015
 
Quality Built In @ Spotify
Quality Built In @ SpotifyQuality Built In @ Spotify
Quality Built In @ Spotify
 
Workshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfWorkshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdf
 
Passing The Joel Test In The PHP World
Passing The Joel Test In The PHP WorldPassing The Joel Test In The PHP World
Passing The Joel Test In The PHP World
 
Become a better UX designer through code
Become a better UX designer through codeBecome a better UX designer through code
Become a better UX designer through code
 
Managing Creativity
Managing CreativityManaging Creativity
Managing Creativity
 
Contributing to Drupal
Contributing to DrupalContributing to Drupal
Contributing to Drupal
 
The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)
 
CodeValue Architecture Next 2018 - Executive track dilemmas and solutions in...
CodeValue Architecture Next 2018 - Executive track  dilemmas and solutions in...CodeValue Architecture Next 2018 - Executive track  dilemmas and solutions in...
CodeValue Architecture Next 2018 - Executive track dilemmas and solutions in...
 
Case Study: Experiences Using IBM Rational Method Composer to Deliver a BPM I...
Case Study: Experiences Using IBM Rational Method Composer to Deliver a BPM I...Case Study: Experiences Using IBM Rational Method Composer to Deliver a BPM I...
Case Study: Experiences Using IBM Rational Method Composer to Deliver a BPM I...
 
Deploy, manage, and customize with SharePoint Patterns and Practices tools an...
Deploy, manage, and customize with SharePoint Patterns and Practices tools an...Deploy, manage, and customize with SharePoint Patterns and Practices tools an...
Deploy, manage, and customize with SharePoint Patterns and Practices tools an...
 
BA and Beyond 20 - Elke Steegmans and David Vandenbroeck - Behaviour-driven d...
BA and Beyond 20 - Elke Steegmans and David Vandenbroeck - Behaviour-driven d...BA and Beyond 20 - Elke Steegmans and David Vandenbroeck - Behaviour-driven d...
BA and Beyond 20 - Elke Steegmans and David Vandenbroeck - Behaviour-driven d...
 
Agile Methodologies And Extreme Programming - Svetlin Nakov
Agile Methodologies And Extreme Programming - Svetlin NakovAgile Methodologies And Extreme Programming - Svetlin Nakov
Agile Methodologies And Extreme Programming - Svetlin Nakov
 
Software System Engineering - Chapter 2
Software System Engineering - Chapter 2Software System Engineering - Chapter 2
Software System Engineering - Chapter 2
 
WDS trainer presentation - MLOps.pptx
WDS trainer presentation - MLOps.pptxWDS trainer presentation - MLOps.pptx
WDS trainer presentation - MLOps.pptx
 
Refactoring, Therapeutic Attitude to Programming.
Refactoring, Therapeutic Attitude to Programming.Refactoring, Therapeutic Attitude to Programming.
Refactoring, Therapeutic Attitude to Programming.
 

Dernier

WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )Pooja Nehwal
 
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AITatiana Gurgel
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...NETWAYS
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Delhi Call girls
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesPooja Nehwal
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...Sheetaleventcompany
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Pooja Nehwal
 
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyCall Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyPooja Nehwal
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Salam Al-Karadaghi
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfhenrik385807
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxmohammadalnahdi22
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024eCommerce Institute
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024eCommerce Institute
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubssamaasim06
 
Mathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptxMathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptxMoumonDas2
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Vipesco
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfhenrik385807
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Chameera Dedduwage
 

Dernier (20)

WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
 
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AI
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
 
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyCall Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubs
 
Mathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptxMathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptx
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)
 

Why refactoring is like sex? Natural Course of Refactoring workflow

  • 1. www.bnsit.pl Natural Course of Refactoring. A refactoring workflow. Mariusz Sieraczkiewicz @ms_bnsit_pl http://msieraczkiewicz.blogspot.com 1
  • 2. www.bnsit.pl Why refactoring is like sex? Natural Course of Refactoring
  • 3. www.bnsit.pl Once you get started, you’ll only stop because you’re exhausted. One mistake and the consequences may be really huge. Why refactoring is like sex? Natural Course of Refactoring 2014 3 (adapted from http://www.thealmightyguru.com/Humor/Docs/ProgrammingIsLikeSex.html)
  • 4. 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. Why refactoring is like sex? Natural Course of Refactoring 2014 4 (adapted from http://www.thealmightyguru.com/Humor/Docs/ProgrammingIsLikeSex.html)
  • 5. 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. Why refactoring is like sex? Natural Course of Refactoring 2014 5 (adapted from http://www.thealmightyguru.com/Humor/Docs/ProgrammingIsLikeSex.html)
  • 6. 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. Why refactoring is like sex? Natural Course of Refactoring 2014 6 (adapted from http://www.thealmightyguru.com/Humor/Docs/ProgrammingIsLikeSex.html)
  • 9. 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 difficult to understand software after some time of its evolution? Natural Course of Refactoring 2014 9
  • 10. 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 programmers productivity in this case? Natural Course of Refactoring 2014 10
  • 11. www.bnsit.pl Flavours of refactoring Natural Course of Refactoring Natural Course of Refactoring 2014 11
  • 12. www.bnsit.pl Two flavours of refactoring Natural Course of Refactoring 2014 12
  • 13. 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 Natural Course of Refactoring 2014 13
  • 14. 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 Natural Course of Refactoring 2014 14
  • 15. www.bnsit.pl When should I do strategic refactoring? Natural Course of Refactoring
  • 16. 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) Simplified version Natural Course of Refactoring 2014 16
  • 17. 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’s Quadrant Natural Course of Refactoring 2014 17 Confront with: • team opinions • business strategy Frequency of changes Complexity
  • 18. www.bnsit.pl Natural Course of Refactoring The process
  • 19. www.bnsit.pl Natural Course of Refactoring 2014 19
  • 20. www.bnsit.pl Step 0. Understand the code Natural Course of Refactoring 2014 20
  • 21. 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 Natural Course of Refactoring 2014 21
  • 22. 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 Natural Course of Refactoring 2014 22
  • 23. 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 Introduce refactoring comments Natural Course of Refactoring 2014 23
  • 24. www.bnsit.pl Step 1. Express algorithm Natural Course of Refactoring 2014 24
  • 25. www.bnsit.pl Aim Code that speaks to you Mental tools • Compose method • Introduce Method Object Refactoring • Extract method Express algorithm Natural Course of Refactoring 2014 25
  • 26. www.bnsit.pl Step 2. Extract responsibilities Natural Course of Refactoring 2014 26
  • 27. 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 Natural Course of Refactoring 2014 27
  • 28. www.bnsit.pl Mental tools Single responsibility principle Move method refactoring Extract class refactoring Introduce Domain Object Introduce Value Object Extract responsibilities Natural Course of Refactoring 2014 28
  • 29. www.bnsit.pl Step 3. Introduce flexibility Natural Course of Refactoring 2014 29
  • 30. 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 need flexibility? Natural Course of Refactoring 2014 30
  • 31. 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 Natural Course of Refactoring 2014 31
  • 32. www.bnsit.pl Mental tools S.O.L.I.D. Design patterns Refactoring to patterns Apply design patterns Natural Course of Refactoring 2014 32
  • 33. www.bnsit.pl Step 4. Evolve architecture Natural Course of Refactoring 2014 33
  • 34. 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 Natural Course of Refactoring 2014 34
  • 35. 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 Natural Course of Refactoring 2014 35
  • 36. Natural Course of Refactoring 2014 36
  • 37. www.bnsit.pl Natural Course of Refactoring 2014 37 Everyday refactoring Strategic refactoring
  • 38. 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 Natural Course of Refactoring 2014 38
  • 39. 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. NCR and architecture Natural Course of Refactoring 2014 39 Techniki pracy z kodem
  • 40. 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 NCR IN A TEAM Natural Course of Refactoring 2014 40
  • 41. www.bnsit.pl Natural Course of Refactoring. A refactoring workflow. Mariusz Sieraczkiewicz @ms_bnsit_pl http://msieraczkiewicz.blogspot.com 41