SlideShare a Scribd company logo
Code Refactoring
Live Coding Demo
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
• Specialised in Re-Engineering of Legacy Code
• “fanatic about code quality”
Training
on the
Job?
Yes, some but...
• only what is already there
• Trial & Error not popular in production
• no practice - only production
• time pressure
I help development teams with
• Professionalism
• Quality and
Productivity
• Continuous
Improvement
Mentoring
• Pair Programming
• Programming
Workshops
• Deliberate
Practice, e.g.
Coding Dojos
Developing Quality
Software Developers
Refactoring is a technique
for restructuring
an existing body of code,
altering its internal structure
without changing
its external behaviour.
(Martin Fowler)
Welcome to the Gilded Rose
The existing inventory system
• We have items to sell. Items degrade in
quality the older they get.
• All items have a SellIn value which denotes
the number of days we have to sell the item.
• All items have a Quality value which denotes
how valuable the item is.
Requirements
• At the end of each day our system lowers both
values for every item.
• Once the sell by date has passed, Quality
degrades twice as fast.
• The Quality of an item is never negative.
• The Quality of an item is never more than 50.
Special Item: Brie
• Aged Brie actually increases in Quality the
older it gets.
Backstage Passes
• Backstage passes,
increases in Quality
as it's SellIn value
approaches (by a
complex formula)
• but Quality drops to
0 after the concert.
Special Item
• Sulfuras, a legendary item, never has to be
sold or decreases in Quality.
New Requirement
• We have recently signed a supplier of
conjured items. This requires an update to our
system:
–Conjured items degrade in Quality twice as
fast as normal items.
What Will We Do Now?
●
I will implement the new requirement.
●
We will change the code together.
●
I will (need) to refactor the existing code.
Demo
Step by step: https://bitbucket.org/pkofler/gilded-rose-refactoring/branch/refactor-7
Code Refactoring - Live Coding Demo (JavaDay 2014)
Code Refactoring - Live Coding Demo (JavaDay 2014)
Code Refactoring - Live Coding Demo (JavaDay 2014)
Now the New Requirement!
• We have recently signed a supplier of
conjured items. This requires an update to our
system:
–Conjured items degrade in Quality twice as
fast as normal items.
What I did
• could not implement the requirement easily,
had to refactor first.
• made it more readable.
• removed duplication (extracted duplicates).
• split method into logically coherent blocks.
What I did
• simplified complex boolean conditions.
• replaced duplicated if-statements with
polymorphy (extracted Strategy pattern).
• moved common code into the strategy.
• finally implemented the new requirement ;-)
Read these books now!
Explore the Refactorings!
Practice them in your IDE!
Peter Kofler
@codecopkofler
www.code-cop.org
Gilded Rose Kata by
Emily Bache
@emilybache
http://coding-is-like-cooking.info/2013/03/writing-good-tests-for-the-gilded-rose-kata/
CC Images
●
Hamster http://www.flickr.com/photos/zebrapares/4529836138
●
master http://www.flickr.com/photos/sherpas428/4350620602/
●
pairing http://www.flickr.com/photos/dav/94735395/
●
inn http://www.flickr.com/photos/danielleblue/170496395/
●
Brie http://www.flickr.com/photos/chez_loulou/2767503201
●
pass http://www.flickr.com/photos/frf_kmeron/5556518514
●
Sulfuras https://www.flickr.com/photos/sharelabs/11195626116

More Related Content

What's hot (20)

PDF
Refactoring the Tennis Kata (2013)
Peter Kofler
 
PDF
Coding Dojo Object Calisthenics (2016)
Peter Kofler
 
PDF
Designing Test Cases for the Gilded Rose Kata v3 (2016)
Peter Kofler
 
PDF
Extract Method Refactoring Workshop (2016)
Peter Kofler
 
PDF
JUnit Boot Camp (GeeCON 2016)
Peter Kofler
 
PDF
Coding Dojo: Functional Calisthenics (2016)
Peter Kofler
 
PDF
Coding Dojo: Data Munging (2016)
Peter Kofler
 
PDF
Designing Test Cases for the Gilded Rose Kata v2 (2015)
Peter Kofler
 
PDF
Coding Dojo: Bank OCR Outside-In (2015)
Peter Kofler
 
PDF
Coding Dojo: Baby Steps Push Challenge (2021)
Peter Kofler
 
PDF
Coding Dojo: Asynchronous Clock-In (2016)
Peter Kofler
 
PDF
TDD and BDD in Sky Deutschland
Murphy Meng
 
PDF
Deliberate Practice, New Learning Styles (2015)
Peter Kofler
 
PDF
Mob Programming (2016)
Peter Kofler
 
PDF
Is Your API Misbehaving (workshop)
Keith Casey
 
PDF
Deliberate Practice (Agile Slovenia 2015)
Peter Kofler
 
PDF
Designing Test Cases for the Gilded Rose Kata (2013)
Peter Kofler
 
PDF
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Peter Kofler
 
PPTX
Production code without tests
Akim Khalilov
 
PDF
Outside-in Test Driven Development - the London School of TDD
Peter Kofler
 
Refactoring the Tennis Kata (2013)
Peter Kofler
 
Coding Dojo Object Calisthenics (2016)
Peter Kofler
 
Designing Test Cases for the Gilded Rose Kata v3 (2016)
Peter Kofler
 
Extract Method Refactoring Workshop (2016)
Peter Kofler
 
JUnit Boot Camp (GeeCON 2016)
Peter Kofler
 
Coding Dojo: Functional Calisthenics (2016)
Peter Kofler
 
Coding Dojo: Data Munging (2016)
Peter Kofler
 
Designing Test Cases for the Gilded Rose Kata v2 (2015)
Peter Kofler
 
Coding Dojo: Bank OCR Outside-In (2015)
Peter Kofler
 
Coding Dojo: Baby Steps Push Challenge (2021)
Peter Kofler
 
Coding Dojo: Asynchronous Clock-In (2016)
Peter Kofler
 
TDD and BDD in Sky Deutschland
Murphy Meng
 
Deliberate Practice, New Learning Styles (2015)
Peter Kofler
 
Mob Programming (2016)
Peter Kofler
 
Is Your API Misbehaving (workshop)
Keith Casey
 
Deliberate Practice (Agile Slovenia 2015)
Peter Kofler
 
Designing Test Cases for the Gilded Rose Kata (2013)
Peter Kofler
 
Using Automated Code Reviews to Achieve Continuous Quality (ASQF Agile Night ...
Peter Kofler
 
Production code without tests
Akim Khalilov
 
Outside-in Test Driven Development - the London School of TDD
Peter Kofler
 

Viewers also liked (20)

PDF
FLTK Summer Course - Part VII - Seventh Impact
Michel Alves
 
PDF
FLTK Summer Course - Part I - First Impact - Exercises
Michel Alves
 
ODP
Servicios web con Python
Manuel Pérez
 
PDF
FLTK Summer Course - Part II - Second Impact - Exercises
Michel Alves
 
PDF
FLTK Summer Course - Part VI - Sixth Impact - Exercises
Michel Alves
 
PDF
FLTK Summer Course - Part III - Third Impact
Michel Alves
 
PDF
Advanced Git
Sergiu-Ioan Ungur
 
PPT
Creating Custom Drupal Modules
tanoshimi
 
PDF
Git hooks For PHP Developers
Umut IŞIK
 
PDF
Using Git on the Command Line
Brian Richards
 
PDF
"Git Hooked!" Using Git hooks to improve your software development process
Polished Geek LLC
 
PDF
Blisstering drupal module development ppt v1.2
Anil Sagar
 
PPTX
Manipulating file in Python
shoukatali500
 
PDF
FLTK Summer Course - Part VIII - Eighth Impact
Michel Alves
 
PPT
Introduction to Git Commands and Concepts
Carl Brown
 
PDF
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
Alessandro Molina
 
PDF
TMS - Schedule of Presentations and Reports
Michel Alves
 
PDF
FLTK Summer Course - Part II - Second Impact
Michel Alves
 
PPT
Minimal standard c program
Swain Loda
 
PPTX
Internal Anatomy of an Update
MongoDB
 
FLTK Summer Course - Part VII - Seventh Impact
Michel Alves
 
FLTK Summer Course - Part I - First Impact - Exercises
Michel Alves
 
Servicios web con Python
Manuel Pérez
 
FLTK Summer Course - Part II - Second Impact - Exercises
Michel Alves
 
FLTK Summer Course - Part VI - Sixth Impact - Exercises
Michel Alves
 
FLTK Summer Course - Part III - Third Impact
Michel Alves
 
Advanced Git
Sergiu-Ioan Ungur
 
Creating Custom Drupal Modules
tanoshimi
 
Git hooks For PHP Developers
Umut IŞIK
 
Using Git on the Command Line
Brian Richards
 
"Git Hooked!" Using Git hooks to improve your software development process
Polished Geek LLC
 
Blisstering drupal module development ppt v1.2
Anil Sagar
 
Manipulating file in Python
shoukatali500
 
FLTK Summer Course - Part VIII - Eighth Impact
Michel Alves
 
Introduction to Git Commands and Concepts
Carl Brown
 
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
Alessandro Molina
 
TMS - Schedule of Presentations and Reports
Michel Alves
 
FLTK Summer Course - Part II - Second Impact
Michel Alves
 
Minimal standard c program
Swain Loda
 
Internal Anatomy of an Update
MongoDB
 
Ad

Similar to Code Refactoring - Live Coding Demo (JavaDay 2014) (20)

PDF
Tale of the Gilded Rose
Lee-Jon Ball
 
PDF
Software Craftsmanship
Manfredi Giordano
 
PPTX
Cutting code quickly
Llewellyn Falco
 
PDF
Cutting Code Quickly - LLEWELLYN FALCO
agilemaine
 
PDF
The Power Of Refactoring (php|tek 09)
Stefan Koopmanschap
 
PDF
The Power Of Refactoring (PHPCon Italia)
Stefan Koopmanschap
 
PDF
Approval Testing & Mutation Testing - Cork Software Crafters - June 2019
Paulo Clavijo
 
PPTX
Practicing Red, Green, Refactor!
XPDays
 
PDF
The Power Of Refactoring (4developers Krakow)
Stefan Koopmanschap
 
PPTX
Refactoring
AngelLuisBlasco
 
PPTX
Refactoring, 2nd Edition
jexp
 
PDF
Refactoring 2 The Max
Alfredo Morresi
 
PDF
Software Refactoring Under Uncertainty: A Robust Multi-Objective Approach
Wiem Mkaouer
 
PDF
Code Refactoring in Software Development
philipthomas428223
 
PDF
agile refactoring and integration techniques.pdf
shreyassoni7
 
PPTX
Code refactoring
Lalit Kale
 
PPTX
Code Refactoring
Milan Vukoje
 
PPTX
SAD10 - Refactoring
Michael Heron
 
PPTX
Understanding the Longevity of Code Smells - Preliminary Results of an Explan...
roberta arcoverde
 
PPTX
Advanced Agile Programming Workshop
AgilePractitionersIL
 
Tale of the Gilded Rose
Lee-Jon Ball
 
Software Craftsmanship
Manfredi Giordano
 
Cutting code quickly
Llewellyn Falco
 
Cutting Code Quickly - LLEWELLYN FALCO
agilemaine
 
The Power Of Refactoring (php|tek 09)
Stefan Koopmanschap
 
The Power Of Refactoring (PHPCon Italia)
Stefan Koopmanschap
 
Approval Testing & Mutation Testing - Cork Software Crafters - June 2019
Paulo Clavijo
 
Practicing Red, Green, Refactor!
XPDays
 
The Power Of Refactoring (4developers Krakow)
Stefan Koopmanschap
 
Refactoring
AngelLuisBlasco
 
Refactoring, 2nd Edition
jexp
 
Refactoring 2 The Max
Alfredo Morresi
 
Software Refactoring Under Uncertainty: A Robust Multi-Objective Approach
Wiem Mkaouer
 
Code Refactoring in Software Development
philipthomas428223
 
agile refactoring and integration techniques.pdf
shreyassoni7
 
Code refactoring
Lalit Kale
 
Code Refactoring
Milan Vukoje
 
SAD10 - Refactoring
Michael Heron
 
Understanding the Longevity of Code Smells - Preliminary Results of an Explan...
roberta arcoverde
 
Advanced Agile Programming Workshop
AgilePractitionersIL
 
Ad

More from Peter Kofler (11)

PDF
Coding Dojo: Naming with Dices (2021)
Peter Kofler
 
PDF
Writing Tests with the Unity Test Framework
Peter Kofler
 
PDF
Pragmatic Introduction to Python Unit Testing (PyDays 2018)
Peter Kofler
 
PDF
Code Retreat Venice (2016)
Peter Kofler
 
PDF
GDCR15 in Las Palmas, Gran Canaria
Peter Kofler
 
PDF
Pair Programming (2015)
Peter Kofler
 
PDF
Pragmatic Introduction to PHP Unit Testing (2015)
Peter Kofler
 
PDF
Coding Dojo: Fun with Tic-Tac-Toe (2014)
Peter Kofler
 
PDF
Coding Dojo: Mars Rover (2014)
Peter Kofler
 
PDF
Coding Dojo: Bank OCR (2014)
Peter Kofler
 
PDF
Prime Factors Code Kata - Practicing TDD (2014)
Peter Kofler
 
Coding Dojo: Naming with Dices (2021)
Peter Kofler
 
Writing Tests with the Unity Test Framework
Peter Kofler
 
Pragmatic Introduction to Python Unit Testing (PyDays 2018)
Peter Kofler
 
Code Retreat Venice (2016)
Peter Kofler
 
GDCR15 in Las Palmas, Gran Canaria
Peter Kofler
 
Pair Programming (2015)
Peter Kofler
 
Pragmatic Introduction to PHP Unit Testing (2015)
Peter Kofler
 
Coding Dojo: Fun with Tic-Tac-Toe (2014)
Peter Kofler
 
Coding Dojo: Mars Rover (2014)
Peter Kofler
 
Coding Dojo: Bank OCR (2014)
Peter Kofler
 
Prime Factors Code Kata - Practicing TDD (2014)
Peter Kofler
 

Recently uploaded (20)

PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 

Code Refactoring - Live Coding Demo (JavaDay 2014)

  • 1. Code Refactoring Live Coding Demo 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 • Specialised in Re-Engineering of Legacy Code • “fanatic about code quality”
  • 4. Yes, some but... • only what is already there • Trial & Error not popular in production • no practice - only production • time pressure
  • 5. I help development teams with • Professionalism • Quality and Productivity • Continuous Improvement
  • 6. Mentoring • Pair Programming • Programming Workshops • Deliberate Practice, e.g. Coding Dojos
  • 8. Refactoring is a technique for restructuring an existing body of code, altering its internal structure without changing its external behaviour. (Martin Fowler)
  • 9. Welcome to the Gilded Rose
  • 10. The existing inventory system • We have items to sell. Items degrade in quality the older they get. • All items have a SellIn value which denotes the number of days we have to sell the item. • All items have a Quality value which denotes how valuable the item is.
  • 11. Requirements • At the end of each day our system lowers both values for every item. • Once the sell by date has passed, Quality degrades twice as fast. • The Quality of an item is never negative. • The Quality of an item is never more than 50.
  • 12. Special Item: Brie • Aged Brie actually increases in Quality the older it gets.
  • 13. Backstage Passes • Backstage passes, increases in Quality as it's SellIn value approaches (by a complex formula) • but Quality drops to 0 after the concert.
  • 14. Special Item • Sulfuras, a legendary item, never has to be sold or decreases in Quality.
  • 15. New Requirement • We have recently signed a supplier of conjured items. This requires an update to our system: –Conjured items degrade in Quality twice as fast as normal items.
  • 16. What Will We Do Now? ● I will implement the new requirement. ● We will change the code together. ● I will (need) to refactor the existing code.
  • 17. Demo Step by step: https://bitbucket.org/pkofler/gilded-rose-refactoring/branch/refactor-7
  • 21. Now the New Requirement! • We have recently signed a supplier of conjured items. This requires an update to our system: –Conjured items degrade in Quality twice as fast as normal items.
  • 22. What I did • could not implement the requirement easily, had to refactor first. • made it more readable. • removed duplication (extracted duplicates). • split method into logically coherent blocks.
  • 23. What I did • simplified complex boolean conditions. • replaced duplicated if-statements with polymorphy (extracted Strategy pattern). • moved common code into the strategy. • finally implemented the new requirement ;-)
  • 24. Read these books now! Explore the Refactorings! Practice them in your IDE!
  • 25. Peter Kofler @codecopkofler www.code-cop.org Gilded Rose Kata by Emily Bache @emilybache http://coding-is-like-cooking.info/2013/03/writing-good-tests-for-the-gilded-rose-kata/
  • 26. CC Images ● Hamster http://www.flickr.com/photos/zebrapares/4529836138 ● master http://www.flickr.com/photos/sherpas428/4350620602/ ● pairing http://www.flickr.com/photos/dav/94735395/ ● inn http://www.flickr.com/photos/danielleblue/170496395/ ● Brie http://www.flickr.com/photos/chez_loulou/2767503201 ● pass http://www.flickr.com/photos/frf_kmeron/5556518514 ● Sulfuras https://www.flickr.com/photos/sharelabs/11195626116