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

PDF
Coding Dojo: Adding Tests to Legacy Code (2014)
PDF
Coding Dojo for Testers/Testing Dojo: Designing Test Cases with FitNesse (2014)
PDF
Clean Readable Specifications (ETC 2016)
PDF
TDD and Related Techniques for Non Developers (2012)
PDF
Brutal Coding Constraints (ITAKE 2017)
ODP
Coding Dojo - Refactoring Tennis Kata
PDF
Concepts of Functional Programming for Java Brains (2010)
PDF
Refactoring the Tennis Kata v2 (2016)
Coding Dojo: Adding Tests to Legacy Code (2014)
Coding Dojo for Testers/Testing Dojo: Designing Test Cases with FitNesse (2014)
Clean Readable Specifications (ETC 2016)
TDD and Related Techniques for Non Developers (2012)
Brutal Coding Constraints (ITAKE 2017)
Coding Dojo - Refactoring Tennis Kata
Concepts of Functional Programming for Java Brains (2010)
Refactoring the Tennis Kata v2 (2016)

What's hot (20)

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

Viewers also liked (20)

PDF
FLTK Summer Course - Part VII - Seventh Impact
PDF
FLTK Summer Course - Part I - First Impact - Exercises
ODP
Servicios web con Python
PDF
FLTK Summer Course - Part II - Second Impact - Exercises
PDF
FLTK Summer Course - Part VI - Sixth Impact - Exercises
PDF
FLTK Summer Course - Part III - Third Impact
PDF
Advanced Git
PPT
Creating Custom Drupal Modules
PDF
Git hooks For PHP Developers
PDF
Using Git on the Command Line
PDF
"Git Hooked!" Using Git hooks to improve your software development process
PDF
Blisstering drupal module development ppt v1.2
PPTX
Manipulating file in Python
PDF
FLTK Summer Course - Part VIII - Eighth Impact
PPT
Introduction to Git Commands and Concepts
PDF
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
PDF
TMS - Schedule of Presentations and Reports
PDF
FLTK Summer Course - Part II - Second Impact
PPT
Minimal standard c program
PPTX
Internal Anatomy of an Update
FLTK Summer Course - Part VII - Seventh Impact
FLTK Summer Course - Part I - First Impact - Exercises
Servicios web con Python
FLTK Summer Course - Part II - Second Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part III - Third Impact
Advanced Git
Creating Custom Drupal Modules
Git hooks For PHP Developers
Using Git on the Command Line
"Git Hooked!" Using Git hooks to improve your software development process
Blisstering drupal module development ppt v1.2
Manipulating file in Python
FLTK Summer Course - Part VIII - Eighth Impact
Introduction to Git Commands and Concepts
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
TMS - Schedule of Presentations and Reports
FLTK Summer Course - Part II - Second Impact
Minimal standard c program
Internal Anatomy of an Update
Ad

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

PDF
Tale of the Gilded Rose
PDF
Software Craftsmanship
PDF
Cutting Code Quickly - LLEWELLYN FALCO
PPTX
Cutting code quickly
PDF
The Power Of Refactoring (php|tek 09)
PDF
The Power Of Refactoring (PHPCon Italia)
PDF
Approval Testing & Mutation Testing - Cork Software Crafters - June 2019
PPTX
Practicing Red, Green, Refactor!
PDF
The Power Of Refactoring (4developers Krakow)
PPTX
Refactoring
PPTX
Refactoring, 2nd Edition
PDF
Refactoring 2 The Max
PDF
Software Refactoring Under Uncertainty: A Robust Multi-Objective Approach
PDF
Code Refactoring in Software Development
PDF
agile refactoring and integration techniques.pdf
PPTX
Code refactoring
PPTX
Code Refactoring
PPTX
SAD10 - Refactoring
PPTX
Understanding the Longevity of Code Smells - Preliminary Results of an Explan...
PPTX
Advanced Agile Programming Workshop
Tale of the Gilded Rose
Software Craftsmanship
Cutting Code Quickly - LLEWELLYN FALCO
Cutting code quickly
The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (PHPCon Italia)
Approval Testing & Mutation Testing - Cork Software Crafters - June 2019
Practicing Red, Green, Refactor!
The Power Of Refactoring (4developers Krakow)
Refactoring
Refactoring, 2nd Edition
Refactoring 2 The Max
Software Refactoring Under Uncertainty: A Robust Multi-Objective Approach
Code Refactoring in Software Development
agile refactoring and integration techniques.pdf
Code refactoring
Code Refactoring
SAD10 - Refactoring
Understanding the Longevity of Code Smells - Preliminary Results of an Explan...
Advanced Agile Programming Workshop

More from Peter Kofler (11)

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

Recently uploaded (20)

PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
The influence of sentiment analysis in enhancing early warning system model f...
PDF
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PDF
Credit Without Borders: AI and Financial Inclusion in Bangladesh
PDF
Comparative analysis of machine learning models for fake news detection in so...
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
A review of recent deep learning applications in wood surface defect identifi...
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PPTX
TEXTILE technology diploma scope and career opportunities
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PPT
Module 1.ppt Iot fundamentals and Architecture
PPTX
The various Industrial Revolutions .pptx
DOCX
search engine optimization ppt fir known well about this
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
Custom Battery Pack Design Considerations for Performance and Safety
Taming the Chaos: How to Turn Unstructured Data into Decisions
Final SEM Unit 1 for mit wpu at pune .pptx
1 - Historical Antecedents, Social Consideration.pdf
The influence of sentiment analysis in enhancing early warning system model f...
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
Credit Without Borders: AI and Financial Inclusion in Bangladesh
Comparative analysis of machine learning models for fake news detection in so...
Getting started with AI Agents and Multi-Agent Systems
A review of recent deep learning applications in wood surface defect identifi...
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
TEXTILE technology diploma scope and career opportunities
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Convolutional neural network based encoder-decoder for efficient real-time ob...
Module 1.ppt Iot fundamentals and Architecture
The various Industrial Revolutions .pptx
search engine optimization ppt fir known well about this
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...

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