SlideShare a Scribd company logo
1 of 39
Download to read offline
The Power of Refactoring




                 Stefan Koopmanschap
    4developers, Krakow, March 7 2009
What will we do?

 What is refactoring?
 Why refactoring?
 Requirements
 HOWTO




                        2
Stefan Koopmanschap
Who is he?




                      3
About me

 Professional Services Consultant at Ibuildings
 10 years of PHP experience
 auto didact
 married, 2 kids, 6 cats, a bunch of fish
 Apple lover
 music addict
 symfony advocate




                                                  4
Refactoring
What is it?




              5
Refactoring is a disciplined technique for restructuring
an existing body of code, altering its internal structure
without changing its external behavior. Its heart is a
series of small behavior preserving transformations.
Each transformation (called a 'refactoring') does little,
but a sequence of transformations can produce a
significant restructuring. Since each refactoring is small,
it's less likely to go wrong. The system is also kept fully
working after each small refactoring, reducing the
chances that a system can get seriously broken during
the restructuring.
(Martin Fowler - Refactoring.com)



                                                              6
Code refactoring is the process of changing a computer
program's code to make it amenable to change,
improve its readability, or simplify its structure, while
preserving its existing functionality.
(Wikipedia)




                                                            7
What

Code refactoring is the process of changing a computer
program's internal structure without modifying its
external behavior or existing functionality.




                                                         8
Why

This is usually done to improve code readability, simplify
code structure, change code to adhere to a given
programming paradigm, improve maintainability, or
improve extensibility.




                                                             9
Improve readability




                      10
Improve maintainability




                          11
Extend/change/implement




                          12
Is it the holy grail?




                        13
Rewrite

A rewrite in computer programming is the act or result of
re-implementing a large portion of existing functionality
without re-use of its source code. When the rewrite is not
using existing code at all, it is common to speak of a
rewrite from scratch. When instead only parts are re-
engineered, which have otherwise become complicated to
handle or extend, then it is more precise to speak of code
refactoring.
(Wikipedia)




                                                         14
Refactor vs Rewrite




                      15
Refactor vs Rewrite

 Refactor whenever it is possible




                                    15
Refactor vs Rewrite

 Refactor whenever it is possible
 Big change? Try to cut it into smaller units




                                                15
Refactor vs Rewrite

 Refactor whenever it is possible
 Big change? Try to cut it into smaller units
 Still have to break the API? Go ahead, and rewrite!




                                                       15
Refactor vs Rewrite

 Refactor whenever it is possible
 Big change? Try to cut it into smaller units
 Still have to break the API? Go ahead, and rewrite!
 Donā€™t take the decision in 5 minutes




                                                       15
Refactor vs Rewrite

Refactoring takes less effort
  Nice for you
  Better for the quality of your work
Breaking the API is more work
  Ensure all calling code is altered as well
  Update your unit tests
  Update your documentation




                                               16
Requirements
for successful refactoring




                             17
Requirements

 Codebase knowledge
 Structured API
 Unit testing




                      18
Codebase knowledge

 Know what to change quickly
 Be aware of your changes
 Be aware of impact of your changes on other components




                                                          19
Structured API

 Refactoring DOES NOT REPLACE design!
 You need a good API that allows internal changes
 Additions to existing APIā€™s should not change existing API
 Keep small ā€œunitsā€




                                                              20
Unit testing




               21
Unit testing

 Unit testing is your first point of QA
 They safeguard you from unexpected side effects
 Test - Change - Test




                                                   22
An example
user authentication




                      23
A test-driven approach




                         24
My first implementation




                          25
My first implementation




                          25
A more dynamic version




                         26
A more dynamic version




                         26
Tips and tricks




                  27
Some tips and tricks

 Write unit tests before you start refactoring
 Code documentation (phpDoc) is your friend
 Donā€™t trust your IDEā€™s refactoring options




                                                 28
Will you refactor now?




                         29
Looking back

 What is refactoring?
 Why do we want to refactor?
 Is it the holy grail?
 Refactoring vs Rewriting
 Requirements
 How to do it
 Tips and tricks




                               30
Creative Commons Rocks!
Readability:
http://www.flickr.com/photos/vipulmathur/
471634239/ (by-nc-sa/2.0)
Maintainability:
http://www.flickr.com/photos/comicbase/
2117680144/ (by-nc-sa/2.0)
Extend:
http://www.flickr.com/photos/auntiep/
221951988/ (by-nc-sa/2.0)
Holy Grail:
http://www.flickr.com/photos/joebeone/
153921142/ (by/2.0)
WĆ¼rst test ever:
http://www.flickr.com/photos/pingles/
1341229619/ (by-nc-nd/2.0)

                                            31
Questions ?




              32
Thank you!
                Contact details:
           Stefan Koopmanschap
  http://www.leftontheweb.com/
      http://www.ibuildings.com/
   http://www.twitter.com/skoop
http://www.slideshare.net/skoop

More Related Content

What's hot

TGT#20 - Automated Tests Only For Testers - Kasper Kulikowski
TGT#20 - Automated Tests Only For Testers - Kasper KulikowskiTGT#20 - Automated Tests Only For Testers - Kasper Kulikowski
TGT#20 - Automated Tests Only For Testers - Kasper KulikowskiTrĆ³jmiejska Grupa Testerska
Ā 
Trunk Based Development in the Enterprise - Its Relevance and Economics
Trunk Based Development in the Enterprise - Its Relevance and EconomicsTrunk Based Development in the Enterprise - Its Relevance and Economics
Trunk Based Development in the Enterprise - Its Relevance and EconomicsPerforce
Ā 
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...VincitOy
Ā 
Testing and beyond at startups
Testing and beyond at startupsTesting and beyond at startups
Testing and beyond at startupsMona Soni
Ā 
Simplified CI/CD Flows for Salesforce via SFDX - Downunder Dreamin - Sydney
Simplified CI/CD Flows for Salesforce via SFDX - Downunder Dreamin - SydneySimplified CI/CD Flows for Salesforce via SFDX - Downunder Dreamin - Sydney
Simplified CI/CD Flows for Salesforce via SFDX - Downunder Dreamin - SydneyAbhinav Gupta
Ā 
Continuos integration with Jenkins for iOS | SuperSpeakers@CodeCamp Iasi, 2014
Continuos integration with Jenkins for iOS | SuperSpeakers@CodeCamp Iasi, 2014Continuos integration with Jenkins for iOS | SuperSpeakers@CodeCamp Iasi, 2014
Continuos integration with Jenkins for iOS | SuperSpeakers@CodeCamp Iasi, 2014Endava
Ā 
Branching and Merging Practices
Branching and Merging Practices Branching and Merging Practices
Branching and Merging Practices Rajesh Kumar
Ā 
Tech Talk #5 : CI/CD FOR MOBILE DEVELOPMENT - Đinh Ngį»c KiĆŖn
Tech Talk #5 : CI/CD FOR MOBILE DEVELOPMENT - Đinh Ngį»c KiĆŖnTech Talk #5 : CI/CD FOR MOBILE DEVELOPMENT - Đinh Ngį»c KiĆŖn
Tech Talk #5 : CI/CD FOR MOBILE DEVELOPMENT - Đinh Ngį»c KiĆŖnNexus FrontierTech
Ā 
Automating development-operations-v1
Automating development-operations-v1Automating development-operations-v1
Automating development-operations-v1Sumanth Vepa
Ā 
ćƒ—ćƒ¬ć‚¼ćƒ³ćƒ“ćƒ•ć‚©ć‚¢ć‚¢ćƒ•ć‚æ
ćƒ—ćƒ¬ć‚¼ćƒ³ćƒ“ćƒ•ć‚©ć‚¢ć‚¢ćƒ•ć‚æćƒ—ćƒ¬ć‚¼ćƒ³ćƒ“ćƒ•ć‚©ć‚¢ć‚¢ćƒ•ć‚æ
ćƒ—ćƒ¬ć‚¼ćƒ³ćƒ“ćƒ•ć‚©ć‚¢ć‚¢ćƒ•ć‚æTsuyoshi Ushio
Ā 
MOPCON 2015 - Tips of Mobile Continuous Delivery
MOPCON 2015 - Tips of Mobile Continuous DeliveryMOPCON 2015 - Tips of Mobile Continuous Delivery
MOPCON 2015 - Tips of Mobile Continuous Deliveryanistar sung
Ā 
Test Driven Design - GDG DevFest Istanbul 2016
Test Driven Design - GDG DevFest Istanbul 2016Test Driven Design - GDG DevFest Istanbul 2016
Test Driven Design - GDG DevFest Istanbul 2016Lemi Orhan Ergin
Ā 
Tech Talk #5 : Apply CI tools in iOS development - Trʰʔng Minh KhƓi
Tech Talk #5 : Apply	CI tools in iOS	development - Trʰʔng Minh KhƓiTech Talk #5 : Apply	CI tools in iOS	development - Trʰʔng Minh KhƓi
Tech Talk #5 : Apply CI tools in iOS development - Trʰʔng Minh KhƓiNexus FrontierTech
Ā 
Build Automation in Android
Build Automation in AndroidBuild Automation in Android
Build Automation in AndroidAngelo RĆ¼ggeberg
Ā 
More than Programming!
More than Programming!More than Programming!
More than Programming!Sophy Eung
Ā 

What's hot (20)

TGT#20 - Automated Tests Only For Testers - Kasper Kulikowski
TGT#20 - Automated Tests Only For Testers - Kasper KulikowskiTGT#20 - Automated Tests Only For Testers - Kasper Kulikowski
TGT#20 - Automated Tests Only For Testers - Kasper Kulikowski
Ā 
Trunk Based Development in the Enterprise - Its Relevance and Economics
Trunk Based Development in the Enterprise - Its Relevance and EconomicsTrunk Based Development in the Enterprise - Its Relevance and Economics
Trunk Based Development in the Enterprise - Its Relevance and Economics
Ā 
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Ā 
Testing and beyond at startups
Testing and beyond at startupsTesting and beyond at startups
Testing and beyond at startups
Ā 
Simplified CI/CD Flows for Salesforce via SFDX - Downunder Dreamin - Sydney
Simplified CI/CD Flows for Salesforce via SFDX - Downunder Dreamin - SydneySimplified CI/CD Flows for Salesforce via SFDX - Downunder Dreamin - Sydney
Simplified CI/CD Flows for Salesforce via SFDX - Downunder Dreamin - Sydney
Ā 
Continuos integration with Jenkins for iOS | SuperSpeakers@CodeCamp Iasi, 2014
Continuos integration with Jenkins for iOS | SuperSpeakers@CodeCamp Iasi, 2014Continuos integration with Jenkins for iOS | SuperSpeakers@CodeCamp Iasi, 2014
Continuos integration with Jenkins for iOS | SuperSpeakers@CodeCamp Iasi, 2014
Ā 
Branching and Merging Practices
Branching and Merging Practices Branching and Merging Practices
Branching and Merging Practices
Ā 
Tech Talk #5 : CI/CD FOR MOBILE DEVELOPMENT - Đinh Ngį»c KiĆŖn
Tech Talk #5 : CI/CD FOR MOBILE DEVELOPMENT - Đinh Ngį»c KiĆŖnTech Talk #5 : CI/CD FOR MOBILE DEVELOPMENT - Đinh Ngį»c KiĆŖn
Tech Talk #5 : CI/CD FOR MOBILE DEVELOPMENT - Đinh Ngį»c KiĆŖn
Ā 
Automating development-operations-v1
Automating development-operations-v1Automating development-operations-v1
Automating development-operations-v1
Ā 
Xp conf-tbd
Xp conf-tbdXp conf-tbd
Xp conf-tbd
Ā 
BDD and Behave
BDD and BehaveBDD and Behave
BDD and Behave
Ā 
JIRA & Stach, The Love Story
JIRA & Stach, The Love StoryJIRA & Stach, The Love Story
JIRA & Stach, The Love Story
Ā 
ćƒ—ćƒ¬ć‚¼ćƒ³ćƒ“ćƒ•ć‚©ć‚¢ć‚¢ćƒ•ć‚æ
ćƒ—ćƒ¬ć‚¼ćƒ³ćƒ“ćƒ•ć‚©ć‚¢ć‚¢ćƒ•ć‚æćƒ—ćƒ¬ć‚¼ćƒ³ćƒ“ćƒ•ć‚©ć‚¢ć‚¢ćƒ•ć‚æ
ćƒ—ćƒ¬ć‚¼ćƒ³ćƒ“ćƒ•ć‚©ć‚¢ć‚¢ćƒ•ć‚æ
Ā 
MOPCON 2015 - Tips of Mobile Continuous Delivery
MOPCON 2015 - Tips of Mobile Continuous DeliveryMOPCON 2015 - Tips of Mobile Continuous Delivery
MOPCON 2015 - Tips of Mobile Continuous Delivery
Ā 
Test Driven Design - GDG DevFest Istanbul 2016
Test Driven Design - GDG DevFest Istanbul 2016Test Driven Design - GDG DevFest Istanbul 2016
Test Driven Design - GDG DevFest Istanbul 2016
Ā 
Tech Talk #5 : Apply CI tools in iOS development - Trʰʔng Minh KhƓi
Tech Talk #5 : Apply	CI tools in iOS	development - Trʰʔng Minh KhƓiTech Talk #5 : Apply	CI tools in iOS	development - Trʰʔng Minh KhƓi
Tech Talk #5 : Apply CI tools in iOS development - Trʰʔng Minh KhƓi
Ā 
Build Automation in Android
Build Automation in AndroidBuild Automation in Android
Build Automation in Android
Ā 
Why I Love Ruby On Rails
Why I Love Ruby On RailsWhy I Love Ruby On Rails
Why I Love Ruby On Rails
Ā 
EVOLVE'15 | Enhance | Rene Ugarte | AEM Quality Assurance
EVOLVE'15 | Enhance | Rene Ugarte | AEM Quality AssuranceEVOLVE'15 | Enhance | Rene Ugarte | AEM Quality Assurance
EVOLVE'15 | Enhance | Rene Ugarte | AEM Quality Assurance
Ā 
More than Programming!
More than Programming!More than Programming!
More than Programming!
Ā 

Similar to The Power Of Refactoring (4developers Krakow)

The Power Of Refactoring (PHPNW)
The Power Of Refactoring (PHPNW)The Power Of Refactoring (PHPNW)
The Power Of Refactoring (PHPNW)Stefan Koopmanschap
Ā 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practicesBill Buchan
Ā 
Paris Web - Javascript as a programming language
Paris Web - Javascript as a programming languageParis Web - Javascript as a programming language
Paris Web - Javascript as a programming languageMarco Cedaro
Ā 
Refactoring workshop
Refactoring workshop Refactoring workshop
Refactoring workshop Itzik Saban
Ā 
Test Driven Design
Test Driven DesignTest Driven Design
Test Driven DesignSaad Ahmed
Ā 
Code refactoring
Code refactoringCode refactoring
Code refactoringLalit Kale
Ā 
Django in the Real World
Django in the Real WorldDjango in the Real World
Django in the Real WorldJacob Kaplan-Moss
Ā 
Software reengineering for Developers
Software reengineering for DevelopersSoftware reengineering for Developers
Software reengineering for DevelopersBradley Irby
Ā 
Refactoring, Emergent Design & Evolutionary Architecture
Refactoring, Emergent Design & Evolutionary ArchitectureRefactoring, Emergent Design & Evolutionary Architecture
Refactoring, Emergent Design & Evolutionary ArchitectureBrad Appleton
Ā 
Refactoring 2 The Max
Refactoring 2 The MaxRefactoring 2 The Max
Refactoring 2 The MaxAlfredo Morresi
Ā 
Principles in Refactoring
Principles in RefactoringPrinciples in Refactoring
Principles in RefactoringChamnap Chhorn
Ā 
Architecture in real
Architecture in realArchitecture in real
Architecture in realMichael Chen
Ā 
10 Tips for Configuring Your Builds with Bamboo Specs
10 Tips for Configuring Your Builds with Bamboo Specs10 Tips for Configuring Your Builds with Bamboo Specs
10 Tips for Configuring Your Builds with Bamboo SpecsAtlassian
Ā 
Effects, Coeffects & Subscriptions: a pit of success for SPAs
Effects, Coeffects & Subscriptions: a pit of success for SPAsEffects, Coeffects & Subscriptions: a pit of success for SPAs
Effects, Coeffects & Subscriptions: a pit of success for SPAsManuel Rivero
Ā 
Continuous integration
Continuous integrationContinuous integration
Continuous integrationBoris Dominic
Ā 
Refactoring - An Introduction
Refactoring - An IntroductionRefactoring - An Introduction
Refactoring - An IntroductionGiorgio Vespucci
Ā 
Simplifying the OpenAPI Development Experience
Simplifying the OpenAPI Development Experience Simplifying the OpenAPI Development Experience
Simplifying the OpenAPI Development Experience confluent
Ā 
Delivery at Scale
Delivery at ScaleDelivery at Scale
Delivery at ScaleAgilar
Ā 

Similar to The Power Of Refactoring (4developers Krakow) (20)

The Power of Refactoring
The Power of RefactoringThe Power of Refactoring
The Power of Refactoring
Ā 
The Power Of Refactoring (PHPNW)
The Power Of Refactoring (PHPNW)The Power Of Refactoring (PHPNW)
The Power Of Refactoring (PHPNW)
Ā 
Refactoring
RefactoringRefactoring
Refactoring
Ā 
The View - Lotusscript coding best practices
The View - Lotusscript coding best practicesThe View - Lotusscript coding best practices
The View - Lotusscript coding best practices
Ā 
Paris Web - Javascript as a programming language
Paris Web - Javascript as a programming languageParis Web - Javascript as a programming language
Paris Web - Javascript as a programming language
Ā 
Refactoring workshop
Refactoring workshop Refactoring workshop
Refactoring workshop
Ā 
Test Driven Design
Test Driven DesignTest Driven Design
Test Driven Design
Ā 
Code refactoring
Code refactoringCode refactoring
Code refactoring
Ā 
Django in the Real World
Django in the Real WorldDjango in the Real World
Django in the Real World
Ā 
Software reengineering for Developers
Software reengineering for DevelopersSoftware reengineering for Developers
Software reengineering for Developers
Ā 
Refactoring, Emergent Design & Evolutionary Architecture
Refactoring, Emergent Design & Evolutionary ArchitectureRefactoring, Emergent Design & Evolutionary Architecture
Refactoring, Emergent Design & Evolutionary Architecture
Ā 
Refactoring 2 The Max
Refactoring 2 The MaxRefactoring 2 The Max
Refactoring 2 The Max
Ā 
Principles in Refactoring
Principles in RefactoringPrinciples in Refactoring
Principles in Refactoring
Ā 
Architecture in real
Architecture in realArchitecture in real
Architecture in real
Ā 
10 Tips for Configuring Your Builds with Bamboo Specs
10 Tips for Configuring Your Builds with Bamboo Specs10 Tips for Configuring Your Builds with Bamboo Specs
10 Tips for Configuring Your Builds with Bamboo Specs
Ā 
Effects, Coeffects & Subscriptions: a pit of success for SPAs
Effects, Coeffects & Subscriptions: a pit of success for SPAsEffects, Coeffects & Subscriptions: a pit of success for SPAs
Effects, Coeffects & Subscriptions: a pit of success for SPAs
Ā 
Continuous integration
Continuous integrationContinuous integration
Continuous integration
Ā 
Refactoring - An Introduction
Refactoring - An IntroductionRefactoring - An Introduction
Refactoring - An Introduction
Ā 
Simplifying the OpenAPI Development Experience
Simplifying the OpenAPI Development Experience Simplifying the OpenAPI Development Experience
Simplifying the OpenAPI Development Experience
Ā 
Delivery at Scale
Delivery at ScaleDelivery at Scale
Delivery at Scale
Ā 

More from Stefan Koopmanschap

A Practical Look At Symfony2
A Practical Look At Symfony2A Practical Look At Symfony2
A Practical Look At Symfony2Stefan Koopmanschap
Ā 
Git for Subversion Users (ZendCon 2011)
Git for Subversion Users (ZendCon 2011)Git for Subversion Users (ZendCon 2011)
Git for Subversion Users (ZendCon 2011)Stefan Koopmanschap
Ā 
A Practical Look at Symfony2 (PHPNW11)
A Practical Look at Symfony2 (PHPNW11)A Practical Look at Symfony2 (PHPNW11)
A Practical Look at Symfony2 (PHPNW11)Stefan Koopmanschap
Ā 
Git For Subversion Users (PHPNW11)
Git For Subversion Users (PHPNW11)Git For Subversion Users (PHPNW11)
Git For Subversion Users (PHPNW11)Stefan Koopmanschap
Ā 
Open Up (International PHP Conference Spring Edition 2011)
Open Up (International PHP Conference Spring Edition 2011)Open Up (International PHP Conference Spring Edition 2011)
Open Up (International PHP Conference Spring Edition 2011)Stefan Koopmanschap
Ā 
Git for Subversion Users (phpDay 2011)
Git for Subversion Users (phpDay 2011)Git for Subversion Users (phpDay 2011)
Git for Subversion Users (phpDay 2011)Stefan Koopmanschap
Ā 
Would you like docs with that? - Zend Webinar
Would you like docs with that? - Zend WebinarWould you like docs with that? - Zend Webinar
Would you like docs with that? - Zend WebinarStefan Koopmanschap
Ā 
Git workshop (2value, 14-12-2010)
Git workshop (2value, 14-12-2010)Git workshop (2value, 14-12-2010)
Git workshop (2value, 14-12-2010)Stefan Koopmanschap
Ā 
Git Workshop (Pfz Workshopdag)
Git Workshop (Pfz Workshopdag)Git Workshop (Pfz Workshopdag)
Git Workshop (Pfz Workshopdag)Stefan Koopmanschap
Ā 
Would you like docs with that? (IPC 2010)
Would you like docs with that? (IPC 2010)Would you like docs with that? (IPC 2010)
Would you like docs with that? (IPC 2010)Stefan Koopmanschap
Ā 
Would you like docs with that? (IPC 2010)
Would you like docs with that? (IPC 2010)Would you like docs with that? (IPC 2010)
Would you like docs with that? (IPC 2010)Stefan Koopmanschap
Ā 
Integrating symfony and Zend Framework (IPC 2010)
Integrating symfony and Zend Framework (IPC 2010)Integrating symfony and Zend Framework (IPC 2010)
Integrating symfony and Zend Framework (IPC 2010)Stefan Koopmanschap
Ā 
Would you like docs with that? (Pfcongres 2010)
Would you like docs with that? (Pfcongres 2010)Would you like docs with that? (Pfcongres 2010)
Would you like docs with that? (Pfcongres 2010)Stefan Koopmanschap
Ā 
The Symfony Community - How to (get) help
The Symfony Community - How to (get) helpThe Symfony Community - How to (get) help
The Symfony Community - How to (get) helpStefan Koopmanschap
Ā 
Integrating symfony and Zend Framework (PHPBarcelona 2009)
Integrating symfony and Zend Framework (PHPBarcelona 2009)Integrating symfony and Zend Framework (PHPBarcelona 2009)
Integrating symfony and Zend Framework (PHPBarcelona 2009)Stefan Koopmanschap
Ā 
Integrating symfony and Zend Framework (PHPNW09)
Integrating symfony and Zend Framework (PHPNW09)Integrating symfony and Zend Framework (PHPNW09)
Integrating symfony and Zend Framework (PHPNW09)Stefan Koopmanschap
Ā 
Integrating symfony and Zend Framework
Integrating symfony and Zend FrameworkIntegrating symfony and Zend Framework
Integrating symfony and Zend FrameworkStefan Koopmanschap
Ā 

More from Stefan Koopmanschap (20)

A Practical Look At Symfony2
A Practical Look At Symfony2A Practical Look At Symfony2
A Practical Look At Symfony2
Ā 
Git for Subversion Users (ZendCon 2011)
Git for Subversion Users (ZendCon 2011)Git for Subversion Users (ZendCon 2011)
Git for Subversion Users (ZendCon 2011)
Ā 
A Practical Look at Symfony2 (PHPNW11)
A Practical Look at Symfony2 (PHPNW11)A Practical Look at Symfony2 (PHPNW11)
A Practical Look at Symfony2 (PHPNW11)
Ā 
Git For Subversion Users (PHPNW11)
Git For Subversion Users (PHPNW11)Git For Subversion Users (PHPNW11)
Git For Subversion Users (PHPNW11)
Ā 
Conference Speaking 101
Conference Speaking 101Conference Speaking 101
Conference Speaking 101
Ā 
Open Up (International PHP Conference Spring Edition 2011)
Open Up (International PHP Conference Spring Edition 2011)Open Up (International PHP Conference Spring Edition 2011)
Open Up (International PHP Conference Spring Edition 2011)
Ā 
Git for Subversion Users (phpDay 2011)
Git for Subversion Users (phpDay 2011)Git for Subversion Users (phpDay 2011)
Git for Subversion Users (phpDay 2011)
Ā 
Would you like docs with that? - Zend Webinar
Would you like docs with that? - Zend WebinarWould you like docs with that? - Zend Webinar
Would you like docs with that? - Zend Webinar
Ā 
Git workshop (2value, 14-12-2010)
Git workshop (2value, 14-12-2010)Git workshop (2value, 14-12-2010)
Git workshop (2value, 14-12-2010)
Ā 
Git Workshop (Pfz Workshopdag)
Git Workshop (Pfz Workshopdag)Git Workshop (Pfz Workshopdag)
Git Workshop (Pfz Workshopdag)
Ā 
Would you like docs with that? (IPC 2010)
Would you like docs with that? (IPC 2010)Would you like docs with that? (IPC 2010)
Would you like docs with that? (IPC 2010)
Ā 
Would you like docs with that? (IPC 2010)
Would you like docs with that? (IPC 2010)Would you like docs with that? (IPC 2010)
Would you like docs with that? (IPC 2010)
Ā 
Integrating symfony and Zend Framework (IPC 2010)
Integrating symfony and Zend Framework (IPC 2010)Integrating symfony and Zend Framework (IPC 2010)
Integrating symfony and Zend Framework (IPC 2010)
Ā 
symfony 1.4 workshop
symfony 1.4 workshopsymfony 1.4 workshop
symfony 1.4 workshop
Ā 
Would you like docs with that? (Pfcongres 2010)
Would you like docs with that? (Pfcongres 2010)Would you like docs with that? (Pfcongres 2010)
Would you like docs with that? (Pfcongres 2010)
Ā 
The Symfony Community - How to (get) help
The Symfony Community - How to (get) helpThe Symfony Community - How to (get) help
The Symfony Community - How to (get) help
Ā 
Integrating symfony and Zend Framework (PHPBarcelona 2009)
Integrating symfony and Zend Framework (PHPBarcelona 2009)Integrating symfony and Zend Framework (PHPBarcelona 2009)
Integrating symfony and Zend Framework (PHPBarcelona 2009)
Ā 
Integrating symfony and Zend Framework (PHPNW09)
Integrating symfony and Zend Framework (PHPNW09)Integrating symfony and Zend Framework (PHPNW09)
Integrating symfony and Zend Framework (PHPNW09)
Ā 
Integrating symfony and Zend Framework
Integrating symfony and Zend FrameworkIntegrating symfony and Zend Framework
Integrating symfony and Zend Framework
Ā 
Scrum (dutch)
Scrum (dutch)Scrum (dutch)
Scrum (dutch)
Ā 

Recently uploaded

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
Ā 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
Ā 
Mcleodganj Call Girls šŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls šŸ„° 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls šŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls šŸ„° 8617370543 Service Offer VIP Hot ModelDeepika Singh
Ā 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
Ā 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
Ā 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
Ā 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
Ā 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
Ā 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
Ā 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
Ā 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
Ā 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
Ā 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
Ā 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
Ā 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
Ā 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
Ā 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
Ā 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
Ā 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
Ā 

Recently uploaded (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Ā 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Ā 
Mcleodganj Call Girls šŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls šŸ„° 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls šŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls šŸ„° 8617370543 Service Offer VIP Hot Model
Ā 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Ā 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Ā 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
Ā 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Ā 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
Ā 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
Ā 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
Ā 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
Ā 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Ā 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Ā 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Ā 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
Ā 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
Ā 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
Ā 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Ā 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
Ā 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
Ā 

The Power Of Refactoring (4developers Krakow)

  • 1. The Power of Refactoring Stefan Koopmanschap 4developers, Krakow, March 7 2009
  • 2. What will we do? What is refactoring? Why refactoring? Requirements HOWTO 2
  • 4. About me Professional Services Consultant at Ibuildings 10 years of PHP experience auto didact married, 2 kids, 6 cats, a bunch of fish Apple lover music addict symfony advocate 4
  • 6. Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a 'refactoring') does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring. (Martin Fowler - Refactoring.com) 6
  • 7. Code refactoring is the process of changing a computer program's code to make it amenable to change, improve its readability, or simplify its structure, while preserving its existing functionality. (Wikipedia) 7
  • 8. What Code refactoring is the process of changing a computer program's internal structure without modifying its external behavior or existing functionality. 8
  • 9. Why This is usually done to improve code readability, simplify code structure, change code to adhere to a given programming paradigm, improve maintainability, or improve extensibility. 9
  • 13. Is it the holy grail? 13
  • 14. Rewrite A rewrite in computer programming is the act or result of re-implementing a large portion of existing functionality without re-use of its source code. When the rewrite is not using existing code at all, it is common to speak of a rewrite from scratch. When instead only parts are re- engineered, which have otherwise become complicated to handle or extend, then it is more precise to speak of code refactoring. (Wikipedia) 14
  • 16. Refactor vs Rewrite Refactor whenever it is possible 15
  • 17. Refactor vs Rewrite Refactor whenever it is possible Big change? Try to cut it into smaller units 15
  • 18. Refactor vs Rewrite Refactor whenever it is possible Big change? Try to cut it into smaller units Still have to break the API? Go ahead, and rewrite! 15
  • 19. Refactor vs Rewrite Refactor whenever it is possible Big change? Try to cut it into smaller units Still have to break the API? Go ahead, and rewrite! Donā€™t take the decision in 5 minutes 15
  • 20. Refactor vs Rewrite Refactoring takes less effort Nice for you Better for the quality of your work Breaking the API is more work Ensure all calling code is altered as well Update your unit tests Update your documentation 16
  • 22. Requirements Codebase knowledge Structured API Unit testing 18
  • 23. Codebase knowledge Know what to change quickly Be aware of your changes Be aware of impact of your changes on other components 19
  • 24. Structured API Refactoring DOES NOT REPLACE design! You need a good API that allows internal changes Additions to existing APIā€™s should not change existing API Keep small ā€œunitsā€ 20
  • 26. Unit testing Unit testing is your first point of QA They safeguard you from unexpected side effects Test - Change - Test 22
  • 31. A more dynamic version 26
  • 32. A more dynamic version 26
  • 34. Some tips and tricks Write unit tests before you start refactoring Code documentation (phpDoc) is your friend Donā€™t trust your IDEā€™s refactoring options 28
  • 35. Will you refactor now? 29
  • 36. Looking back What is refactoring? Why do we want to refactor? Is it the holy grail? Refactoring vs Rewriting Requirements How to do it Tips and tricks 30
  • 37. Creative Commons Rocks! Readability: http://www.flickr.com/photos/vipulmathur/ 471634239/ (by-nc-sa/2.0) Maintainability: http://www.flickr.com/photos/comicbase/ 2117680144/ (by-nc-sa/2.0) Extend: http://www.flickr.com/photos/auntiep/ 221951988/ (by-nc-sa/2.0) Holy Grail: http://www.flickr.com/photos/joebeone/ 153921142/ (by/2.0) WĆ¼rst test ever: http://www.flickr.com/photos/pingles/ 1341229619/ (by-nc-nd/2.0) 31
  • 39. Thank you! Contact details: Stefan Koopmanschap http://www.leftontheweb.com/ http://www.ibuildings.com/ http://www.twitter.com/skoop http://www.slideshare.net/skoop