SlideShare a Scribd company logo
1 of 38
Download to read offline
Refactoring
Introduction
(Extract Method)
February 2016
Peter Kofler, ‘Code Cop’
@codecopkofler
www.code-cop.org
Copyright Peter Kofler, licensed under CC-BY.
Peter Kofler
• Ph.D. (Appl. Math.)
• Professional Software
Developer for 15 years
• “fanatic about code quality”
• Freelance Code Mentor
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
I help development teams with
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
●
Professionalism
●
Quality and
Productivity
●
Continuous
Improvement
Mentoring
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
●
Pair Programming
●
Programming
Workshops
●
Deliberate
Practice, e.g.
Coding Dojos
Developing Quality
Software Developers
Workshop Structure
●
Simple Design
●
Code Smells
●
Refactoring
●
Refactor manually
●
Refactoring tools
(i.e. PHPStorm)
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Coding Dojo Mindset
●
Safe place outside
work
●
We are here to learn
●
Need to slow down
●
Focus on doing it right
●
Collaborative Game
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Software Design
Why Software Design?
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Software Design
Enables Change
Four Rules of Simple Design
(1) Passes the tests
(2) No duplication
(3) Reveals intention
(4) Fewer elements
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
"single letter variables who
the fuck do you think you are"
http://theprofoundprogrammer.com/post/26561881517/text-single-letter-variables-who-the-fuck-do
… that's a Code Smells
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Code Smell
●
“a surface indication that usually
indicates a deeper problem in the
system.“
●
quick to spot
●
e.g. bad names
●
e.g. long method
●
e.g. duplication
●
does not always indicate a problem
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
List of Code Smells (Fowler)
The Bloaters
- Long Method
- Large Class
- Primitive Obsession
- Long Parameter List
- DataClumps
The Object-Orientation Abusers
- Switch Statements
- Temporary Field
- Refused Bequest
- Alternative Classes with Different
Interfaces
The Change Preventers
- Divergent Change
- Shotgun Surgery
- Parallel Inheritance Hierarchies
The Dispensables
- Lazy class
- Data class
- Duplicate Code
- Dead Code
- Speculative Generality
The Couplers
- Feature Envy
- Inappropriate Intimacy
- Message Chains
- Middle Man
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Comment explaining
section of code
●
code grouped
into blocks
and there is
a comment
above each
few lines of
code
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
# delete previously converted BAS
File.delete PRG if File.exist? PRG
Dir['*.BAS'].each { |bas| File.delete bas }
# convert basic PRG to readable format
Dir['*.PRG'].each do |prg|
# handles only 8.3 names, rename
File.rename(prg, PRG)
puts "converting #{prg}" +
`#{CBM2ASC} #{PRG} #{BAS} b`
File.rename(BAS,
prg.sub(/.PRG$/i,'.BAS'))
end
# delete converted PRG
Dir['*.PRG'].each { |prg| File.delete prg }
Duplicate Code
●
same code found in 2 or more places
●
e.g. formatting, is user in session?
●
same expression found in 2 or more
places in the same function
●
constant value found in 2 or more places
●
e.g. items per page, default encoding
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Method does too much
●
has more than 5 lines of code
●
If in doubt – it's too big.
●
does different things
●
e.g. DB and UI
●
has strange name or
●
has 'and' in its name
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Code Smell Exercise
●
Group into pairs.
●
Get the printout of the Tennis code.
●
Read the code carefully.
●
Mark found code smells.
●
where? and which?
●
maybe more smells in one line
●
We found 25, how many can you find?
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
How do we fix it?
Refactoring
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Definition
Refactoring is a technique
for restructuring
an existing body of code,
altering its internal structure
without changing
its external behaviour.
(Martin Fowler)
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Small Transformations
●
behaviour preserving transformation
●
each transformation is small, less likely
to go wrong
●
system is fully working after each change
●
verified by working tests
●
sequence of transformations produce a
significant restructuring
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Extract Method
● Create a new method, name by intention
● Copy extracted code from source method to new method
● Scan for local variables.
● Temporary variables local to method?
● Local-scope variables modified?
Return changes back to parent method.
● Pass local-scope variables as parameters.
● (Compile.)
● Replace extracted code with call to new method.
● (Compile and) test.
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Introduce (Explaining) Variable
●
Declare a (final) temporary variable.
●
Set it to the result of part of the expression.
●
Replace the result part of the expression
with the value of the temp.
●
If the result part of the expression is repeated,
you can replace the repeats one at a time.
●
(Compile and) test.
●
Repeat for other parts of the expression.
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Refactoring Exercise
●
Group into new pairs (with computer).
●
Go to the Tennis project.
●
Run ./vendor/bin/phpunit
●
Open TennisGame2.php in text editor.
●
Extract >= 2 methods (by hand).
●
Extract >= 2 local expressions (by hand).
●
Extract >= 2 constant (by hand).
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Refactor Mercilessly
Seriously ;-)
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
●
mer·ci·less is defined as
having or showing no mercy,
cold-blooded, hard-boiled,
heartless, insensitive, hard,
pitiless, remorseless, ruthless,
slash-and-burn, soulless,
take-no-prisoners,
unfeeling, unsympathetic
●
e.g. „extract till you drop“
https://sites.google.com/site/unclebobconsultingllc/one-thing-extract-till-you-drop
Find more in the Refactoring
Book
Refactoring Questions
●
How long is a long method?
●
How do we refactor?
●
During refactoring, how
long does code not compile?
●
When to run the tests?
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Refactoring with Tools
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Automatic Refactorings
(PHPStorm)
● Rename
● Change Signature
● Move
● Extract Variable
● Extract Constant
● Extract Field
● Extract Method
● Extract Parameter
● Inline
● Safe Delete
● Copy/Clone
● Extract Interface
● Pull Members up
● Push Members down
JavaScript:
● Change Signature
● Extract Variable
● Extract Parameter
● (Format)
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Demo(Refactoring in PHPStorm)
PHPStorm Exercise
●
Group into new pairs.
●
Open Gilded Rose project in PHPStorm.
●
On folder test, select Run Tests
●
Open gilded_rose.php.
●
Clean up in small steps.
●
Try to use only automatic refactorings.
●
Run tests often.
●
Commit to Git whenever tests pass.
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
What you could do
●
Make it more readable.
●
Remove duplication (extract duplicates).
●
Split into logically coherent blocks.
●
Simplify complex boolean conditions.
●
Bonus Round: Replace duplicated if-
statements with polymorphism (extract
Strategy pattern).
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Closing Circle
●
What did you learn today?
●
What surprised you today?
●
What will you do
differently in the
future?
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
created by Peter Kofler
@codecopkofler
www.code-cop.org
with help from Aki Salmi
@rinkkasatiainen
https://about.me/rinkkasatiainen
both katas by Emily Bache
@emilybache
http://coding-is-like-cooking.info/2011/08/refactoring-kata-fun/
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
CC Images
●
puzzle https://www.flickr.com/photos/lizadaly/2944362379/
●
todos http://www.flickr.com/photos/kylesteeddesign/3724074594/
●
dojo http://www.flickr.com/photos/49715404@N00/3267627038/
●
wants you http://www.flickr.com/photos/shutter/105497713/
●
boys https://www.flickr.com/photos/andymorffew/16925347231/
●
smells http://www.flickr.com/photos/hhbw/4215183405/
●
exercise https://www.flickr.com/photos/sanchom/2963072255/
●
mercy http://www.flickr.com/photos/williac/99551756/
●
questions http://www.flickr.com/photos/seandreilinger/2326448445/
●
tools https://www.flickr.com/photos/tom-margie/5019211728/
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

More Related Content

What's hot

Coding Dojo: Data Munging (2016)
Coding Dojo: Data Munging (2016)Coding Dojo: Data Munging (2016)
Coding Dojo: Data Munging (2016)Peter Kofler
 
JUnit Boot Camp (GeeCON 2016)
JUnit Boot Camp (GeeCON 2016)JUnit Boot Camp (GeeCON 2016)
JUnit Boot Camp (GeeCON 2016)Peter Kofler
 
Designing Test Cases for the Gilded Rose Kata (2013)
Designing Test Cases for the Gilded Rose Kata (2013)Designing Test Cases for the Gilded Rose Kata (2013)
Designing Test Cases for the Gilded Rose Kata (2013)Peter Kofler
 
Idiomatic R for Rosetta Code (2013)
Idiomatic R for Rosetta Code (2013)Idiomatic R for Rosetta Code (2013)
Idiomatic R for Rosetta Code (2013)Peter Kofler
 
Outside-in Test Driven Development - the London School of TDD
Outside-in Test Driven Development - the London School of TDDOutside-in Test Driven Development - the London School of TDD
Outside-in Test Driven Development - the London School of TDDPeter Kofler
 
Refactoring the Tennis Kata v2 (2016)
Refactoring the Tennis Kata v2 (2016)Refactoring the Tennis Kata v2 (2016)
Refactoring the Tennis Kata v2 (2016)Peter Kofler
 
The Brutal Refactoring Game (2013)
The Brutal Refactoring Game (2013)The Brutal Refactoring Game (2013)
The Brutal Refactoring Game (2013)Peter Kofler
 
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...Peter Kofler
 
Brutal Coding Constraints (ITAKE 2017)
Brutal Coding Constraints (ITAKE 2017)Brutal Coding Constraints (ITAKE 2017)
Brutal Coding Constraints (ITAKE 2017)Peter Kofler
 
TDD as if You Meant It (2013)
TDD as if You Meant It (2013)TDD as if You Meant It (2013)
TDD as if You Meant It (2013)Peter Kofler
 
Mob Programming (2016)
Mob Programming (2016)Mob Programming (2016)
Mob Programming (2016)Peter Kofler
 
Designing Test Cases for the Gilded Rose Kata v3 (2016)
Designing Test Cases for the Gilded Rose Kata v3 (2016)Designing Test Cases for the Gilded Rose Kata v3 (2016)
Designing Test Cases for the Gilded Rose Kata v3 (2016)Peter Kofler
 
Software Craftsmanship Journeyman Tour (2013)
Software Craftsmanship Journeyman Tour (2013)Software Craftsmanship Journeyman Tour (2013)
Software Craftsmanship Journeyman Tour (2013)Peter Kofler
 
Coding Dojo: Asynchronous Clock-In (2016)
Coding Dojo: Asynchronous Clock-In (2016)Coding Dojo: Asynchronous Clock-In (2016)
Coding Dojo: Asynchronous Clock-In (2016)Peter Kofler
 
Designing Test Cases for the Gilded Rose Kata v2 (2015)
Designing Test Cases for the Gilded Rose Kata v2 (2015)Designing Test Cases for the Gilded Rose Kata v2 (2015)
Designing Test Cases for the Gilded Rose Kata v2 (2015)Peter Kofler
 
Coding Dojo Object Calisthenics (2016)
Coding Dojo Object Calisthenics (2016)Coding Dojo Object Calisthenics (2016)
Coding Dojo Object Calisthenics (2016)Peter Kofler
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkPeter Kofler
 
Coding Dojo: Adding Tests to Legacy Code (2014)
Coding Dojo: Adding Tests to Legacy Code (2014)Coding Dojo: Adding Tests to Legacy Code (2014)
Coding Dojo: Adding Tests to Legacy Code (2014)Peter Kofler
 
Code Retreat Venice (2016)
Code Retreat Venice (2016)Code Retreat Venice (2016)
Code Retreat Venice (2016)Peter Kofler
 
Code Retreat Graz, Austria 2013
Code Retreat Graz, Austria 2013Code Retreat Graz, Austria 2013
Code Retreat Graz, Austria 2013Peter Kofler
 

What's hot (20)

Coding Dojo: Data Munging (2016)
Coding Dojo: Data Munging (2016)Coding Dojo: Data Munging (2016)
Coding Dojo: Data Munging (2016)
 
JUnit Boot Camp (GeeCON 2016)
JUnit Boot Camp (GeeCON 2016)JUnit Boot Camp (GeeCON 2016)
JUnit Boot Camp (GeeCON 2016)
 
Designing Test Cases for the Gilded Rose Kata (2013)
Designing Test Cases for the Gilded Rose Kata (2013)Designing Test Cases for the Gilded Rose Kata (2013)
Designing Test Cases for the Gilded Rose Kata (2013)
 
Idiomatic R for Rosetta Code (2013)
Idiomatic R for Rosetta Code (2013)Idiomatic R for Rosetta Code (2013)
Idiomatic R for Rosetta Code (2013)
 
Outside-in Test Driven Development - the London School of TDD
Outside-in Test Driven Development - the London School of TDDOutside-in Test Driven Development - the London School of TDD
Outside-in Test Driven Development - the London School of TDD
 
Refactoring the Tennis Kata v2 (2016)
Refactoring the Tennis Kata v2 (2016)Refactoring the Tennis Kata v2 (2016)
Refactoring the Tennis Kata v2 (2016)
 
The Brutal Refactoring Game (2013)
The Brutal Refactoring Game (2013)The Brutal Refactoring Game (2013)
The Brutal Refactoring Game (2013)
 
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
 
Brutal Coding Constraints (ITAKE 2017)
Brutal Coding Constraints (ITAKE 2017)Brutal Coding Constraints (ITAKE 2017)
Brutal Coding Constraints (ITAKE 2017)
 
TDD as if You Meant It (2013)
TDD as if You Meant It (2013)TDD as if You Meant It (2013)
TDD as if You Meant It (2013)
 
Mob Programming (2016)
Mob Programming (2016)Mob Programming (2016)
Mob Programming (2016)
 
Designing Test Cases for the Gilded Rose Kata v3 (2016)
Designing Test Cases for the Gilded Rose Kata v3 (2016)Designing Test Cases for the Gilded Rose Kata v3 (2016)
Designing Test Cases for the Gilded Rose Kata v3 (2016)
 
Software Craftsmanship Journeyman Tour (2013)
Software Craftsmanship Journeyman Tour (2013)Software Craftsmanship Journeyman Tour (2013)
Software Craftsmanship Journeyman Tour (2013)
 
Coding Dojo: Asynchronous Clock-In (2016)
Coding Dojo: Asynchronous Clock-In (2016)Coding Dojo: Asynchronous Clock-In (2016)
Coding Dojo: Asynchronous Clock-In (2016)
 
Designing Test Cases for the Gilded Rose Kata v2 (2015)
Designing Test Cases for the Gilded Rose Kata v2 (2015)Designing Test Cases for the Gilded Rose Kata v2 (2015)
Designing Test Cases for the Gilded Rose Kata v2 (2015)
 
Coding Dojo Object Calisthenics (2016)
Coding Dojo Object Calisthenics (2016)Coding Dojo Object Calisthenics (2016)
Coding Dojo Object Calisthenics (2016)
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
 
Coding Dojo: Adding Tests to Legacy Code (2014)
Coding Dojo: Adding Tests to Legacy Code (2014)Coding Dojo: Adding Tests to Legacy Code (2014)
Coding Dojo: Adding Tests to Legacy Code (2014)
 
Code Retreat Venice (2016)
Code Retreat Venice (2016)Code Retreat Venice (2016)
Code Retreat Venice (2016)
 
Code Retreat Graz, Austria 2013
Code Retreat Graz, Austria 2013Code Retreat Graz, Austria 2013
Code Retreat Graz, Austria 2013
 

Viewers also liked

Digital Optimisation Infographic - Forrester Report
Digital Optimisation Infographic - Forrester ReportDigital Optimisation Infographic - Forrester Report
Digital Optimisation Infographic - Forrester ReportOmer Celep
 
My favorite (mostly) free social media tools
My favorite (mostly) free social media toolsMy favorite (mostly) free social media tools
My favorite (mostly) free social media toolsJay Dolan
 
Lugar de encuentro y aprendizaje, una renovación de los parques infantiles
Lugar de encuentro  y aprendizaje, una renovación de los parques infantilesLugar de encuentro  y aprendizaje, una renovación de los parques infantiles
Lugar de encuentro y aprendizaje, una renovación de los parques infantilesBertaAparicio14
 
Build competitive edge through differentiated customer experience
Build competitive edge through differentiated customer experienceBuild competitive edge through differentiated customer experience
Build competitive edge through differentiated customer experienceIntense Technologies Limited
 
Oprah ( halima ahmed)
Oprah ( halima ahmed)Oprah ( halima ahmed)
Oprah ( halima ahmed)7aloom
 
OPRAH WINFREY
OPRAH WINFREYOPRAH WINFREY
OPRAH WINFREYshilu37
 
Practica de windows
Practica de windows Practica de windows
Practica de windows Norman Lucero
 
Mandarin Phonetic
Mandarin Phonetic Mandarin Phonetic
Mandarin Phonetic Devy Riani
 
Tax Problems with Big Box Stores
Tax Problems with Big Box StoresTax Problems with Big Box Stores
Tax Problems with Big Box Storesfsbrlaw
 
Trabajo Cooperativo sobre Animales invertebrados
Trabajo Cooperativo sobre Animales invertebradosTrabajo Cooperativo sobre Animales invertebrados
Trabajo Cooperativo sobre Animales invertebradosAlquimista Aula
 
Sap plant-maintenance-pm-business-blueprint-bbp2
Sap plant-maintenance-pm-business-blueprint-bbp2Sap plant-maintenance-pm-business-blueprint-bbp2
Sap plant-maintenance-pm-business-blueprint-bbp2gabrielsyst
 
La famille Simpson
La famille SimpsonLa famille Simpson
La famille Simpsonsmt786
 

Viewers also liked (17)

Digital Optimisation Infographic - Forrester Report
Digital Optimisation Infographic - Forrester ReportDigital Optimisation Infographic - Forrester Report
Digital Optimisation Infographic - Forrester Report
 
My favorite (mostly) free social media tools
My favorite (mostly) free social media toolsMy favorite (mostly) free social media tools
My favorite (mostly) free social media tools
 
Lugar de encuentro y aprendizaje, una renovación de los parques infantiles
Lugar de encuentro  y aprendizaje, una renovación de los parques infantilesLugar de encuentro  y aprendizaje, una renovación de los parques infantiles
Lugar de encuentro y aprendizaje, una renovación de los parques infantiles
 
Estrategias de divulgación y posicionamiento de marca
Estrategias de divulgación y posicionamiento  de marcaEstrategias de divulgación y posicionamiento  de marca
Estrategias de divulgación y posicionamiento de marca
 
Portfolio_Dino
Portfolio_DinoPortfolio_Dino
Portfolio_Dino
 
Build competitive edge through differentiated customer experience
Build competitive edge through differentiated customer experienceBuild competitive edge through differentiated customer experience
Build competitive edge through differentiated customer experience
 
Tratao de Zimmermann
Tratao de ZimmermannTratao de Zimmermann
Tratao de Zimmermann
 
Oprah ( halima ahmed)
Oprah ( halima ahmed)Oprah ( halima ahmed)
Oprah ( halima ahmed)
 
OPRAH WINFREY
OPRAH WINFREYOPRAH WINFREY
OPRAH WINFREY
 
Practica de windows
Practica de windows Practica de windows
Practica de windows
 
Mandarin Phonetic
Mandarin Phonetic Mandarin Phonetic
Mandarin Phonetic
 
Tax Problems with Big Box Stores
Tax Problems with Big Box StoresTax Problems with Big Box Stores
Tax Problems with Big Box Stores
 
Alien museo 2.odp
Alien museo 2.odpAlien museo 2.odp
Alien museo 2.odp
 
Trabajo Cooperativo sobre Animales invertebrados
Trabajo Cooperativo sobre Animales invertebradosTrabajo Cooperativo sobre Animales invertebrados
Trabajo Cooperativo sobre Animales invertebrados
 
Sap plant-maintenance-pm-business-blueprint-bbp2
Sap plant-maintenance-pm-business-blueprint-bbp2Sap plant-maintenance-pm-business-blueprint-bbp2
Sap plant-maintenance-pm-business-blueprint-bbp2
 
La famille Simpson
La famille SimpsonLa famille Simpson
La famille Simpson
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
 

Similar to Extract Method Refactoring Workshop (2016)

Pragmatic Introduction to Python Unit Testing (PyDays 2018)
Pragmatic Introduction to Python Unit Testing (PyDays 2018)Pragmatic Introduction to Python Unit Testing (PyDays 2018)
Pragmatic Introduction to Python Unit Testing (PyDays 2018)Peter Kofler
 
Code Quality Assurance v4 (2013)
Code Quality Assurance v4 (2013)Code Quality Assurance v4 (2013)
Code Quality Assurance v4 (2013)Peter Kofler
 
Prime Factors Code Kata - Practicing TDD (2014)
Prime Factors Code Kata - Practicing TDD (2014)Prime Factors Code Kata - Practicing TDD (2014)
Prime Factors Code Kata - Practicing TDD (2014)Peter Kofler
 
Pragmatic Introduction to PHP Unit Testing (2015)
Pragmatic Introduction to PHP Unit Testing (2015)Pragmatic Introduction to PHP Unit Testing (2015)
Pragmatic Introduction to PHP Unit Testing (2015)Peter Kofler
 
Coding Dojo: Baby Steps (2014)
Coding Dojo: Baby Steps (2014)Coding Dojo: Baby Steps (2014)
Coding Dojo: Baby Steps (2014)Peter Kofler
 
Coding Dojo: String Calculator (2013)
Coding Dojo: String Calculator (2013)Coding Dojo: String Calculator (2013)
Coding Dojo: String Calculator (2013)Peter Kofler
 
Code refactoring workshop (in Javascript)
Code refactoring workshop (in Javascript)Code refactoring workshop (in Javascript)
Code refactoring workshop (in Javascript)Ilias Bartolini
 
Coding Dojo: Roman Numerals (2014)
Coding Dojo: Roman Numerals (2014)Coding Dojo: Roman Numerals (2014)
Coding Dojo: Roman Numerals (2014)Peter Kofler
 
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020Andrew Yatsenko
 
Dmytro Dziubenko "Developer's toolchain"
Dmytro Dziubenko "Developer's toolchain"Dmytro Dziubenko "Developer's toolchain"
Dmytro Dziubenko "Developer's toolchain"Fwdays
 
Pair Programming (2015)
Pair Programming (2015)Pair Programming (2015)
Pair Programming (2015)Peter Kofler
 
Can PL/SQL be Clean? (2013)
Can PL/SQL be Clean? (2013)Can PL/SQL be Clean? (2013)
Can PL/SQL be Clean? (2013)Peter Kofler
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy CodeAndrea Polci
 
Webpack & React Performance in 16+ Steps
Webpack & React Performance in 16+ StepsWebpack & React Performance in 16+ Steps
Webpack & React Performance in 16+ StepsGrgur Grisogono
 
Coding Dojo: Bank OCR (2014)
Coding Dojo: Bank OCR (2014)Coding Dojo: Bank OCR (2014)
Coding Dojo: Bank OCR (2014)Peter Kofler
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your codePascal Larocque
 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Editionjexp
 
Containerized build
Containerized buildContainerized build
Containerized buildDaniel Foo
 
Dev + DevOps для PHP розробника
Dev + DevOps для PHP розробникаDev + DevOps для PHP розробника
Dev + DevOps для PHP розробникаphpfriendsclub
 
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.Chris Laning
 

Similar to Extract Method Refactoring Workshop (2016) (20)

Pragmatic Introduction to Python Unit Testing (PyDays 2018)
Pragmatic Introduction to Python Unit Testing (PyDays 2018)Pragmatic Introduction to Python Unit Testing (PyDays 2018)
Pragmatic Introduction to Python Unit Testing (PyDays 2018)
 
Code Quality Assurance v4 (2013)
Code Quality Assurance v4 (2013)Code Quality Assurance v4 (2013)
Code Quality Assurance v4 (2013)
 
Prime Factors Code Kata - Practicing TDD (2014)
Prime Factors Code Kata - Practicing TDD (2014)Prime Factors Code Kata - Practicing TDD (2014)
Prime Factors Code Kata - Practicing TDD (2014)
 
Pragmatic Introduction to PHP Unit Testing (2015)
Pragmatic Introduction to PHP Unit Testing (2015)Pragmatic Introduction to PHP Unit Testing (2015)
Pragmatic Introduction to PHP Unit Testing (2015)
 
Coding Dojo: Baby Steps (2014)
Coding Dojo: Baby Steps (2014)Coding Dojo: Baby Steps (2014)
Coding Dojo: Baby Steps (2014)
 
Coding Dojo: String Calculator (2013)
Coding Dojo: String Calculator (2013)Coding Dojo: String Calculator (2013)
Coding Dojo: String Calculator (2013)
 
Code refactoring workshop (in Javascript)
Code refactoring workshop (in Javascript)Code refactoring workshop (in Javascript)
Code refactoring workshop (in Javascript)
 
Coding Dojo: Roman Numerals (2014)
Coding Dojo: Roman Numerals (2014)Coding Dojo: Roman Numerals (2014)
Coding Dojo: Roman Numerals (2014)
 
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
 
Dmytro Dziubenko "Developer's toolchain"
Dmytro Dziubenko "Developer's toolchain"Dmytro Dziubenko "Developer's toolchain"
Dmytro Dziubenko "Developer's toolchain"
 
Pair Programming (2015)
Pair Programming (2015)Pair Programming (2015)
Pair Programming (2015)
 
Can PL/SQL be Clean? (2013)
Can PL/SQL be Clean? (2013)Can PL/SQL be Clean? (2013)
Can PL/SQL be Clean? (2013)
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy Code
 
Webpack & React Performance in 16+ Steps
Webpack & React Performance in 16+ StepsWebpack & React Performance in 16+ Steps
Webpack & React Performance in 16+ Steps
 
Coding Dojo: Bank OCR (2014)
Coding Dojo: Bank OCR (2014)Coding Dojo: Bank OCR (2014)
Coding Dojo: Bank OCR (2014)
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Edition
 
Containerized build
Containerized buildContainerized build
Containerized build
 
Dev + DevOps для PHP розробника
Dev + DevOps для PHP розробникаDev + DevOps для PHP розробника
Dev + DevOps для PHP розробника
 
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
 

Recently uploaded

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

Extract Method Refactoring Workshop (2016)

  • 1. Refactoring Introduction (Extract Method) February 2016 Peter Kofler, ‘Code Cop’ @codecopkofler www.code-cop.org Copyright Peter Kofler, licensed under CC-BY.
  • 2. Peter Kofler • Ph.D. (Appl. Math.) • Professional Software Developer for 15 years • “fanatic about code quality” • Freelance Code Mentor PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 3. I help development teams with PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY ● Professionalism ● Quality and Productivity ● Continuous Improvement
  • 4. Mentoring PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY ● Pair Programming ● Programming Workshops ● Deliberate Practice, e.g. Coding Dojos
  • 6. Workshop Structure ● Simple Design ● Code Smells ● Refactoring ● Refactor manually ● Refactoring tools (i.e. PHPStorm) PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 7. Coding Dojo Mindset ● Safe place outside work ● We are here to learn ● Need to slow down ● Focus on doing it right ● Collaborative Game PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 9. Why Software Design? PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 11. Four Rules of Simple Design (1) Passes the tests (2) No duplication (3) Reveals intention (4) Fewer elements PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 12. "single letter variables who the fuck do you think you are" http://theprofoundprogrammer.com/post/26561881517/text-single-letter-variables-who-the-fuck-do
  • 13. … that's a Code Smells PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 14. Code Smell ● “a surface indication that usually indicates a deeper problem in the system.“ ● quick to spot ● e.g. bad names ● e.g. long method ● e.g. duplication ● does not always indicate a problem PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 15. List of Code Smells (Fowler) The Bloaters - Long Method - Large Class - Primitive Obsession - Long Parameter List - DataClumps The Object-Orientation Abusers - Switch Statements - Temporary Field - Refused Bequest - Alternative Classes with Different Interfaces The Change Preventers - Divergent Change - Shotgun Surgery - Parallel Inheritance Hierarchies The Dispensables - Lazy class - Data class - Duplicate Code - Dead Code - Speculative Generality The Couplers - Feature Envy - Inappropriate Intimacy - Message Chains - Middle Man PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 16. Comment explaining section of code ● code grouped into blocks and there is a comment above each few lines of code PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY # delete previously converted BAS File.delete PRG if File.exist? PRG Dir['*.BAS'].each { |bas| File.delete bas } # convert basic PRG to readable format Dir['*.PRG'].each do |prg| # handles only 8.3 names, rename File.rename(prg, PRG) puts "converting #{prg}" + `#{CBM2ASC} #{PRG} #{BAS} b` File.rename(BAS, prg.sub(/.PRG$/i,'.BAS')) end # delete converted PRG Dir['*.PRG'].each { |prg| File.delete prg }
  • 17. Duplicate Code ● same code found in 2 or more places ● e.g. formatting, is user in session? ● same expression found in 2 or more places in the same function ● constant value found in 2 or more places ● e.g. items per page, default encoding PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 18. Method does too much ● has more than 5 lines of code ● If in doubt – it's too big. ● does different things ● e.g. DB and UI ● has strange name or ● has 'and' in its name PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 19. Code Smell Exercise ● Group into pairs. ● Get the printout of the Tennis code. ● Read the code carefully. ● Mark found code smells. ● where? and which? ● maybe more smells in one line ● We found 25, how many can you find? PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 20. How do we fix it?
  • 21. Refactoring PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 22. Definition Refactoring is a technique for restructuring an existing body of code, altering its internal structure without changing its external behaviour. (Martin Fowler) PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 23. Small Transformations ● behaviour preserving transformation ● each transformation is small, less likely to go wrong ● system is fully working after each change ● verified by working tests ● sequence of transformations produce a significant restructuring PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 24. Extract Method ● Create a new method, name by intention ● Copy extracted code from source method to new method ● Scan for local variables. ● Temporary variables local to method? ● Local-scope variables modified? Return changes back to parent method. ● Pass local-scope variables as parameters. ● (Compile.) ● Replace extracted code with call to new method. ● (Compile and) test. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 25. Introduce (Explaining) Variable ● Declare a (final) temporary variable. ● Set it to the result of part of the expression. ● Replace the result part of the expression with the value of the temp. ● If the result part of the expression is repeated, you can replace the repeats one at a time. ● (Compile and) test. ● Repeat for other parts of the expression. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 26. Refactoring Exercise ● Group into new pairs (with computer). ● Go to the Tennis project. ● Run ./vendor/bin/phpunit ● Open TennisGame2.php in text editor. ● Extract >= 2 methods (by hand). ● Extract >= 2 local expressions (by hand). ● Extract >= 2 constant (by hand). PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 28. Seriously ;-) PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY ● mer·ci·less is defined as having or showing no mercy, cold-blooded, hard-boiled, heartless, insensitive, hard, pitiless, remorseless, ruthless, slash-and-burn, soulless, take-no-prisoners, unfeeling, unsympathetic ● e.g. „extract till you drop“ https://sites.google.com/site/unclebobconsultingllc/one-thing-extract-till-you-drop
  • 29. Find more in the Refactoring Book
  • 30. Refactoring Questions ● How long is a long method? ● How do we refactor? ● During refactoring, how long does code not compile? ● When to run the tests? PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 31. Refactoring with Tools PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 32. Automatic Refactorings (PHPStorm) ● Rename ● Change Signature ● Move ● Extract Variable ● Extract Constant ● Extract Field ● Extract Method ● Extract Parameter ● Inline ● Safe Delete ● Copy/Clone ● Extract Interface ● Pull Members up ● Push Members down JavaScript: ● Change Signature ● Extract Variable ● Extract Parameter ● (Format) PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 34. PHPStorm Exercise ● Group into new pairs. ● Open Gilded Rose project in PHPStorm. ● On folder test, select Run Tests ● Open gilded_rose.php. ● Clean up in small steps. ● Try to use only automatic refactorings. ● Run tests often. ● Commit to Git whenever tests pass. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 35. What you could do ● Make it more readable. ● Remove duplication (extract duplicates). ● Split into logically coherent blocks. ● Simplify complex boolean conditions. ● Bonus Round: Replace duplicated if- statements with polymorphism (extract Strategy pattern). PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 36. Closing Circle ● What did you learn today? ● What surprised you today? ● What will you do differently in the future? PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 37. created by Peter Kofler @codecopkofler www.code-cop.org with help from Aki Salmi @rinkkasatiainen https://about.me/rinkkasatiainen both katas by Emily Bache @emilybache http://coding-is-like-cooking.info/2011/08/refactoring-kata-fun/ PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  • 38. CC Images ● puzzle https://www.flickr.com/photos/lizadaly/2944362379/ ● todos http://www.flickr.com/photos/kylesteeddesign/3724074594/ ● dojo http://www.flickr.com/photos/49715404@N00/3267627038/ ● wants you http://www.flickr.com/photos/shutter/105497713/ ● boys https://www.flickr.com/photos/andymorffew/16925347231/ ● smells http://www.flickr.com/photos/hhbw/4215183405/ ● exercise https://www.flickr.com/photos/sanchom/2963072255/ ● mercy http://www.flickr.com/photos/williac/99551756/ ● questions http://www.flickr.com/photos/seandreilinger/2326448445/ ● tools https://www.flickr.com/photos/tom-margie/5019211728/ PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY