Refactoring - An Introduction

Giorgio Vespucci
Giorgio VespucciSr. Software Dev Engineer at Expedia Group / Capgemini Italy Consultant at Capgemini Engineering
Refactoring
An Introduction




Giorgio Vespucci
“Software must be soft: it
has to be easy to change
because it will change
despite our misguided
efforts otherwise.”
        The Pragmatic Programmers
What we want


Robustness
Simplicity
Softness
What we see




  Fragility
 Complexity
  Rigidity
Unreadable
  code is…
Hard to modify
Duplicated
    code is…
Hard to modify
Complex
code is…
Hard to modify
Refactored
code is...
Easier to
understand
Cheaper
 to modify
Clean
  code
Better
  code
Refactored
code shows...
Changes to its
internal structure
But no change to
observable behavior
“So what?”
Try to understand
this Java code
java.util.Calendar c = 
  java.util.Calendar.getInstance();
c.set(2005, java.util.Calendar.NOVEMBER, 20);
c.getTime();
Uhm... a Date...
And now this code
october(23,2008);
Hey, mum! It's a Date!
“Any fool
can write code
that a computer
can understand.”
“Good programmers write
code
that humans
can understand.”
               Martin Fowler - Refactoring
What do we
need ?
“If you want to refactor, the essential
     precondition is having solid tests.”
                        Martin Fowler - Refactoring
Measures matter
Where to start ?
Look at
the code
Sniff
the code
Does it smell ?
Duupliccateed code?
Loooooong method?
L a r g e class?
The Refactoring cycle
1) Choose the worst smell

2) Select a refactoring

3) Apply the refactoring

4) Run all the tests
little   steps
Great
results
Must-have books on Refactoring

Refactoring: Improving the Design of Existing
Code
(Addison-Wesley Object Technology Series)
Martin Fowler

Refactoring Workbook
(Addison-Wesley Object Technology Series)
 William C. Wake

Refactoring to Patterns
(Addison-Wesley Signature Series)
Joshua Kerievsky
Online resources

Smells to refactor
http://wiki.java.net/bin/view/People/SmellsToRefactorings

Alpha list of refactoring
http://www.refactoring.com/catalog/index.html

Refactoring Workbook Website
http://xp123.com/rwb/

Refactoring to Patterns catalog
http://industriallogic.com/xp/refactoring/catalog.html
1 of 40

Recommended

Principles in Refactoring by
Principles in RefactoringPrinciples in Refactoring
Principles in RefactoringChamnap Chhorn
3.4K views18 slides
Refactoring Tips by Martin Fowler by
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerIgor Crvenov
24.1K views66 slides
Refactoring 101 by
Refactoring 101Refactoring 101
Refactoring 101Adam Culp
7.1K views46 slides
Refactoring: Improve the design of existing code by
Refactoring: Improve the design of existing codeRefactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeValerio Maggio
4.5K views43 slides
Unit testing legacy code by
Unit testing legacy codeUnit testing legacy code
Unit testing legacy codeLars Thorup
2K views31 slides
Code Refactoring by
Code RefactoringCode Refactoring
Code Refactoringkim.mens
4.2K views81 slides

More Related Content

What's hot

Getting Unstuck: Working with Legacy Code and Data by
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataCory Foy
1.9K views49 slides
VT.NET 20160411: An Intro to Test Driven Development (TDD) by
VT.NET 20160411: An Intro to Test Driven Development (TDD)VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)Rob Hale
445 views24 slides
Refactoring Applications using SOLID Principles by
Refactoring Applications using SOLID PrinciplesRefactoring Applications using SOLID Principles
Refactoring Applications using SOLID PrinciplesSteven Smith
10.5K views56 slides
Introduction to TDD (Test Driven development) - Ahmed Shreef by
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefAhmed Shreef
1.4K views32 slides
Adding Unit Test To Legacy Code by
Adding Unit Test To Legacy CodeAdding Unit Test To Legacy Code
Adding Unit Test To Legacy CodeTerry Yin
2.3K views28 slides
Working Effectively with Legacy Code: Lessons in Practice by
Working Effectively with Legacy Code: Lessons in PracticeWorking Effectively with Legacy Code: Lessons in Practice
Working Effectively with Legacy Code: Lessons in PracticeAmar Shah
644 views33 slides

What's hot(20)

Getting Unstuck: Working with Legacy Code and Data by Cory Foy
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and Data
Cory Foy1.9K views
VT.NET 20160411: An Intro to Test Driven Development (TDD) by Rob Hale
VT.NET 20160411: An Intro to Test Driven Development (TDD)VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)
Rob Hale445 views
Refactoring Applications using SOLID Principles by Steven Smith
Refactoring Applications using SOLID PrinciplesRefactoring Applications using SOLID Principles
Refactoring Applications using SOLID Principles
Steven Smith10.5K views
Introduction to TDD (Test Driven development) - Ahmed Shreef by Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed Shreef
Ahmed Shreef1.4K views
Adding Unit Test To Legacy Code by Terry Yin
Adding Unit Test To Legacy CodeAdding Unit Test To Legacy Code
Adding Unit Test To Legacy Code
Terry Yin2.3K views
Working Effectively with Legacy Code: Lessons in Practice by Amar Shah
Working Effectively with Legacy Code: Lessons in PracticeWorking Effectively with Legacy Code: Lessons in Practice
Working Effectively with Legacy Code: Lessons in Practice
Amar Shah644 views
Test driven development and unit testing with examples in C++ by Hong Le Van
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
Hong Le Van755 views
Pitfalls Of Tdd Adoption by Bartosz Bankowski by Agileee
Pitfalls Of Tdd Adoption by Bartosz BankowskiPitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz Bankowski
Agileee731 views
iOS Test-Driven Development by Pablo Villar
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
Pablo Villar1.5K views
TDD reloaded - JUGTAA 24 Ottobre 2012 by Pietro Di Bello
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
Pietro Di Bello483 views
Refactoring Techniques by Mayada Ghanem
Refactoring TechniquesRefactoring Techniques
Refactoring Techniques
Mayada Ghanem1.6K views
Unit testing - the hard parts by Shaun Abram
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard parts
Shaun Abram1.6K views
Test Driven Development (TDD) by David Ehringer
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
David Ehringer31.9K views
TDD and the Legacy Code Black Hole by Noam Kfir
TDD and the Legacy Code Black HoleTDD and the Legacy Code Black Hole
TDD and the Legacy Code Black Hole
Noam Kfir514 views
Working With Legacy Code by Andrea Polci
Working With Legacy CodeWorking With Legacy Code
Working With Legacy Code
Andrea Polci3.7K views
Test Driven Development by Dhaval Dalal
Test Driven DevelopmentTest Driven Development
Test Driven Development
Dhaval Dalal2.5K views

Viewers also liked

The Decorator Pattern by
The Decorator PatternThe Decorator Pattern
The Decorator PatternAkshat Vig
3.4K views11 slides
Introduction to Design Pattern by
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design PatternSanae BEKKAR
17K views31 slides
Code Refactoring by
Code RefactoringCode Refactoring
Code RefactoringCharlie Berg
3.2K views16 slides
Design patterns by
Design patternsDesign patterns
Design patternsabhisheksagi
14.9K views28 slides
Refactoring by
RefactoringRefactoring
RefactoringArtem Tabalin
10.3K views102 slides
Design Patterns這樣學就會了:入門班 Day1 教材 by
Design Patterns這樣學就會了:入門班 Day1 教材Design Patterns這樣學就會了:入門班 Day1 教材
Design Patterns這樣學就會了:入門班 Day1 教材teddysoft
108.9K views78 slides

Viewers also liked(9)

The Decorator Pattern by Akshat Vig
The Decorator PatternThe Decorator Pattern
The Decorator Pattern
Akshat Vig3.4K views
Introduction to Design Pattern by Sanae BEKKAR
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
Sanae BEKKAR17K views
Design patterns by abhisheksagi
Design patternsDesign patterns
Design patterns
abhisheksagi14.9K views
Design Patterns這樣學就會了:入門班 Day1 教材 by teddysoft
Design Patterns這樣學就會了:入門班 Day1 教材Design Patterns這樣學就會了:入門班 Day1 教材
Design Patterns這樣學就會了:入門班 Day1 教材
teddysoft108.9K views
Design Patterns Illustrated by Herman Peeren
Design Patterns IllustratedDesign Patterns Illustrated
Design Patterns Illustrated
Herman Peeren42.7K views
Design Patterns - 01 Introduction and Decorator Pattern by eprafulla
Design Patterns - 01 Introduction and Decorator PatternDesign Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator Pattern
eprafulla4.6K views
Design Patterns by soms_1
Design PatternsDesign Patterns
Design Patterns
soms_114.2K views

Similar to Refactoring - An Introduction

Refactoring, 2nd Edition by
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Editionjexp
2.4K views128 slides
Test Driven Development - Workshop by
Test Driven Development - WorkshopTest Driven Development - Workshop
Test Driven Development - WorkshopAnjana Somathilake
1.2K views44 slides
Refactoring 2 The Max by
Refactoring 2 The MaxRefactoring 2 The Max
Refactoring 2 The MaxAlfredo Morresi
1.1K views22 slides
Test Driven Design - GDG DevFest Istanbul 2016 by
Test Driven Design - GDG DevFest Istanbul 2016Test Driven Design - GDG DevFest Istanbul 2016
Test Driven Design - GDG DevFest Istanbul 2016Lemi Orhan Ergin
244.5K views46 slides
Test Driven Design by
Test Driven DesignTest Driven Design
Test Driven DesignSaad Ahmed
144 views46 slides
The Power Of Refactoring (4developers Krakow) by
The Power Of Refactoring (4developers Krakow)The Power Of Refactoring (4developers Krakow)
The Power Of Refactoring (4developers Krakow)Stefan Koopmanschap
1.5K views39 slides

Similar to Refactoring - An Introduction(20)

Refactoring, 2nd Edition by jexp
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Edition
jexp2.4K views
Test Driven Design - GDG DevFest Istanbul 2016 by Lemi Orhan Ergin
Test Driven Design - GDG DevFest Istanbul 2016Test Driven Design - GDG DevFest Istanbul 2016
Test Driven Design - GDG DevFest Istanbul 2016
Lemi Orhan Ergin244.5K views
Test Driven Design by Saad Ahmed
Test Driven DesignTest Driven Design
Test Driven Design
Saad Ahmed144 views
The Power Of Refactoring (4developers Krakow) by Stefan Koopmanschap
The Power Of Refactoring (4developers Krakow)The Power Of Refactoring (4developers Krakow)
The Power Of Refactoring (4developers Krakow)
Stefan Koopmanschap1.5K views
New Ideas for Old Code - Greach by HamletDRC
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - Greach
HamletDRC1.1K views
Paris Web - Javascript as a programming language by Marco Cedaro
Paris Web - Javascript as a programming languageParis Web - Javascript as a programming language
Paris Web - Javascript as a programming language
Marco Cedaro11.5K views
Lessons Learned in Software Development: QA Infrastructure – Maintaining Rob... by Cωνσtantίnoς Giannoulis
Lessons Learned in Software Development: QA Infrastructure – Maintaining Rob...Lessons Learned in Software Development: QA Infrastructure – Maintaining Rob...
Lessons Learned in Software Development: QA Infrastructure – Maintaining Rob...
Howto Test A Patch And Make A Difference! by Joel Farris
Howto Test A Patch And Make A Difference!Howto Test A Patch And Make A Difference!
Howto Test A Patch And Make A Difference!
Joel Farris600 views
Programming in Java: Getting Started by Martin Chapman
Programming in Java: Getting StartedProgramming in Java: Getting Started
Programming in Java: Getting Started
Martin Chapman248 views
AOTB2014: Agile Testing on the Java Platform by Peter Pilgrim
AOTB2014: Agile Testing on the Java PlatformAOTB2014: Agile Testing on the Java Platform
AOTB2014: Agile Testing on the Java Platform
Peter Pilgrim1K views
PHP Mega Meetup, Sep, 2020, Anti patterns in php by Ahmed Abdou
PHP Mega Meetup, Sep, 2020, Anti patterns in phpPHP Mega Meetup, Sep, 2020, Anti patterns in php
PHP Mega Meetup, Sep, 2020, Anti patterns in php
Ahmed Abdou86 views
Refactoring, A First Example by Vorleak Chy
Refactoring, A First ExampleRefactoring, A First Example
Refactoring, A First Example
Vorleak Chy900 views
Refactoring 2TheMax (con ReSharper) by DotNetMarche
Refactoring 2TheMax (con ReSharper)Refactoring 2TheMax (con ReSharper)
Refactoring 2TheMax (con ReSharper)
DotNetMarche567 views
Clean Code - The Next Chapter by Victor Rentea
Clean Code - The Next ChapterClean Code - The Next Chapter
Clean Code - The Next Chapter
Victor Rentea2.5K views
Few minutes To better Code - Refactoring by Diaa Al-Salehi
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - Refactoring
Diaa Al-Salehi318 views

Recently uploaded

20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
41 views73 slides
Business Analyst Series 2023 - Week 3 Session 5 by
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5DianaGray10
300 views20 slides
Ransomware is Knocking your Door_Final.pdf by
Ransomware is Knocking your Door_Final.pdfRansomware is Knocking your Door_Final.pdf
Ransomware is Knocking your Door_Final.pdfSecurity Bootcamp
59 views46 slides
PRODUCT LISTING.pptx by
PRODUCT LISTING.pptxPRODUCT LISTING.pptx
PRODUCT LISTING.pptxangelicacueva6
14 views1 slide
Special_edition_innovator_2023.pdf by
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdfWillDavies22
18 views6 slides
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院IttrainingIttraining
58 views8 slides

Recently uploaded(20)

Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10300 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2218 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb14 views
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf by Dr. Jimmy Schwarzkopf
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn22 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson92 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi132 views
Unit 1_Lecture 2_Physical Design of IoT.pdf by StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec12 views
Future of AR - Facebook Presentation by ssuserb54b561
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
ssuserb54b56115 views

Refactoring - An Introduction