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

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
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
PPTX
Symfony2 for legacy app rejuvenation: the eZ Publish case study
PPTX
How I Learned to Stop Worrying and Love Legacy Code.....
ZIP
Staging and Deployment
PPT
How to write bad code using C#
KEY
Get your Project back in Shape!
PDF
eXtreme Programming
PPTX
Austin Elixir: Slack Bots With Hedwig
PPTX
Refactor your code: when, why and how?
PPTX
Technical Excellence Doesn't Just Happen - AgileIndy 2016
PPT
Building a Simple Theme Framework
PDF
Technical Excellence Doesn't Just Happen--Igniting a Craftsmanship Culture
PPTX
Refactoring Legacy Code - true story
PDF
CDC 3D Printing Energy Light
PDF
Prime Factors Code Kata (2010)
PDF
An Introduction To Software Development - Final Review
PPTX
Software testing and quality assurance
PDF
The bigrewrite
PDF
SE2016 Java Alex Theedom "Java EE revisits design patterns"
PDF
Alex Theedom Java ee revisits design patterns
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Symfony2 for legacy app rejuvenation: the eZ Publish case study
How I Learned to Stop Worrying and Love Legacy Code.....
Staging and Deployment
How to write bad code using C#
Get your Project back in Shape!
eXtreme Programming
Austin Elixir: Slack Bots With Hedwig
Refactor your code: when, why and how?
Technical Excellence Doesn't Just Happen - AgileIndy 2016
Building a Simple Theme Framework
Technical Excellence Doesn't Just Happen--Igniting a Craftsmanship Culture
Refactoring Legacy Code - true story
CDC 3D Printing Energy Light
Prime Factors Code Kata (2010)
An Introduction To Software Development - Final Review
Software testing and quality assurance
The bigrewrite
SE2016 Java Alex Theedom "Java EE revisits design patterns"
Alex Theedom Java ee revisits design patterns

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
Spectral efficient network and resource selection model in 5G networks
PPTX
MYSQL Presentation for SQL database connectivity
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
KodekX | Application Modernization Development
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Modernizing your data center with Dell and AMD
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation theory and applications.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Approach and Philosophy of On baking technology
Spectral efficient network and resource selection model in 5G networks
MYSQL Presentation for SQL database connectivity
“AI and Expert System Decision Support & Business Intelligence Systems”
Advanced methodologies resolving dimensionality complications for autism neur...
KodekX | Application Modernization Development
The Rise and Fall of 3GPP – Time for a Sabbatical?
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Diabetes mellitus diagnosis method based random forest with bat algorithm
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Modernizing your data center with Dell and AMD
Mobile App Security Testing_ A Comprehensive Guide.pdf
cuic standard and advanced reporting.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Empathic Computing: Creating Shared Understanding
Unlocking AI with Model Context Protocol (MCP)
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Electronic commerce courselecture one. Pdf
Encapsulation theory and applications.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Approach and Philosophy of On baking technology

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