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
Ad

Recommended

Coding Dojo: Adding Tests to Legacy Code (2014)
Coding Dojo: Adding Tests to Legacy Code (2014)
Peter Kofler
 
Coding Dojo for Testers/Testing Dojo: Designing Test Cases with FitNesse (2014)
Coding Dojo for Testers/Testing Dojo: Designing Test Cases with FitNesse (2014)
Peter Kofler
 
Clean Readable Specifications (ETC 2016)
Clean Readable Specifications (ETC 2016)
Peter Kofler
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)
Peter Kofler
 
Brutal Coding Constraints (ITAKE 2017)
Brutal Coding Constraints (ITAKE 2017)
Peter Kofler
 
Coding Dojo - Refactoring Tennis Kata
Coding Dojo - Refactoring Tennis Kata
Alin Pandichi
 
Concepts of Functional Programming for Java Brains (2010)
Concepts of Functional Programming for Java Brains (2010)
Peter Kofler
 
Refactoring the Tennis Kata v2 (2016)
Refactoring the Tennis Kata v2 (2016)
Peter Kofler
 
Refactoring the Tennis Kata (2013)
Refactoring the Tennis Kata (2013)
Peter Kofler
 
Coding Dojo Object Calisthenics (2016)
Coding Dojo Object Calisthenics (2016)
Peter Kofler
 
Designing Test Cases for the Gilded Rose Kata v3 (2016)
Designing Test Cases for the Gilded Rose Kata v3 (2016)
Peter Kofler
 
Extract Method Refactoring Workshop (2016)
Extract Method Refactoring Workshop (2016)
Peter Kofler
 
JUnit Boot Camp (GeeCON 2016)
JUnit Boot Camp (GeeCON 2016)
Peter Kofler
 
Coding Dojo: Functional Calisthenics (2016)
Coding Dojo: Functional Calisthenics (2016)
Peter Kofler
 
Coding Dojo: Data Munging (2016)
Coding Dojo: Data Munging (2016)
Peter Kofler
 
Designing Test Cases for the Gilded Rose Kata v2 (2015)
Designing Test Cases for the Gilded Rose Kata v2 (2015)
Peter Kofler
 
Coding Dojo: Bank OCR Outside-In (2015)
Coding Dojo: Bank OCR Outside-In (2015)
Peter Kofler
 
Coding Dojo: Baby Steps Push Challenge (2021)
Coding Dojo: Baby Steps Push Challenge (2021)
Peter Kofler
 
Coding Dojo: Asynchronous Clock-In (2016)
Coding Dojo: Asynchronous Clock-In (2016)
Peter Kofler
 
TDD and BDD in Sky Deutschland
TDD and BDD in Sky Deutschland
Murphy Meng
 
Deliberate Practice, New Learning Styles (2015)
Deliberate Practice, New Learning Styles (2015)
Peter Kofler
 
Mob Programming (2016)
Mob Programming (2016)
Peter Kofler
 
Is Your API Misbehaving (workshop)
Is Your API Misbehaving (workshop)
Keith Casey
 
Deliberate Practice (Agile Slovenia 2015)
Deliberate Practice (Agile Slovenia 2015)
Peter Kofler
 
Designing Test Cases for the Gilded Rose Kata (2013)
Designing Test Cases for the Gilded Rose Kata (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 ...
Peter Kofler
 
Production code without tests
Production code without tests
Akim Khalilov
 
Outside-in Test Driven Development - the London School of TDD
Outside-in Test Driven Development - the London School of TDD
Peter Kofler
 
FLTK Summer Course - Part VII - Seventh Impact
FLTK Summer Course - Part VII - Seventh Impact
Michel Alves
 
FLTK Summer Course - Part I - First Impact - Exercises
FLTK Summer Course - Part I - First Impact - Exercises
Michel Alves
 

More Related Content

What's hot (20)

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

Viewers also liked (20)

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

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

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

More from Peter Kofler (11)

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

Recently uploaded (20)

AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe 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