SlideShare une entreprise Scribd logo
1  sur  33
Télécharger pour lire hors ligne
Professional Refactoring
International PHP Conference 2009
Spring Edition




                                    Mayflower GmbH 2009   1
• Senior Developer / Team Lead at
  Mayflower GmbH
 • Reporting and Rating Apps
 • QA and PHP 5 Migration
   consultings
• PHP since 1999 (3.0.16)
• phpMyFAQ since 2001



                                    Mayflower GmbH 2009   2
Who are you?

 • What are you doing?
 • What‘s your team size?
 • Using MVC?
 • Who‘s using Continous Integration?
   • PHPUnit?
   • 80% code coverage?




                                        Mayflower GmbH 2009   3
Your projects...
• What‘s your average project lifetime?
• Is there PHP code more than 5 years old?
• How many lines of code?
• How many change requests per year?
• Has there been a specification?
• Were all features in the first
  release as specified?




                                             Mayflower GmbH 2009   4
What is Refactoring?


 „Refactoring is a disciplined technique for
 restructuring an existing body of code, altering
 its internal structure without changing its
 external behavior.“
                        -Martin Fowler, www.refactoring.com




                                                              Mayflower GmbH 2009   5
Why especially PHP?

                      (c) www.medrehab.com




        Code Aging!
                                   Mayflower GmbH 2009   6
A PHP Project in 2000 ...
• no coding standards, no PHPDoc
• no MVC, no Design Patterns
• if you were lucky, someone used a
  template system
• nobody cared about XSS or CSRF
  a lot of changes in business logics
• never got refactored,
  documentated or even tested ...



                                        Mayflower GmbH 2009   7
... because it worked!



                     Mayflower GmbH 2009   8
In the year 2009
• change requests get more and
  more expensive
• the bug rate is always
  increasing
• the development team
  motivation is decreasing
• requirement changes are
  almost impossible
• new team members need a lot
  of time to be productive
                                 Mayflower GmbH 2009   9
Management point of view

Costs per Change Request



                           rising frequency




                                         Dead end!




                                          Benefit per Change Request
                                                                      Mayflower GmbH 2009   10
Start refactoring now!
                    Mayflower GmbH 2009   11
But hey, stop!
                 Mayflower GmbH 2009   12
Don‘t refactor ...
• weeks before a
  important release
• only with a lot of junior
  developers
• parallel with
  development tasks




                              Mayflower GmbH 2009   13
Before starting refactoring

• define a coding standard
 • avoids spaghetti code
 • speeds up maintainability
 • improves productivity
• fix your API specs
• complete your documentation




                                Mayflower GmbH 2009   14
During the refactoring...
       • stay calm
       • take a lot of good developers and
         a bunch of juniors
       • write tests, tests, tests
       • don‘t let developer refactor their
         own code
       • don‘t let junior developers
         refactor alone

                                          Mayflower GmbH 2009   15
About Unittests
• Testing is essential during refactoring
• Problems
  • most of old code isn‘t
    „unittestable“
  • API breaks during refacotoring
• Solution
  • Selenium tests instead
  • iterative refactoring


                                            Mayflower GmbH 2009   16
(c) BMW AG




             Okay, let‘s start!
                              Mayflower GmbH 2009   17
Back to Martin Fowler


 „Refactoring is a disciplined technique for
 restructuring an existing body of code, altering
 its internal structure without changing its
 external behavior.“
                        -Martin Fowler, www.refactoring.com




                                                              Mayflower GmbH 2009   18
Forms of refactoring

•Renaming
•Extraction
•Changing signature
•Pull up / Pull down

                       Mayflower GmbH 2009   19
Renaming

     /**
       * Remove a word from the stop word dictionary
       *
       * @param integer $id
       *
       * @return void
       */
     public function remove($id)
     {
          $sql = sprintf(quot;DELETE FROM $this->tablename WHERE id = %d AND lang =
 '%s'quot;, $id, $this->language);

         $this->db->query($sql);
     }




                                                                           Mayflower GmbH 2009   20
Renaming

     /**
       * Remove a word from the stop word dictionary
       *
       * @param integer $stopword_id ID of the stop word
       *
       * @return void
       */
     public function remove($stopword_id)
     {
          $delete = sprintf(quot;DELETE FROM $this->tablename WHERE id = %d AND lang =
 '%s'quot;, $stopword_id, $this->language);

         $this->db->query($delete);
     }




                                                                           Mayflower GmbH 2009   21
Restructuring

      /**
        * Remove a word from the stop word dictionary
        *
        * @param integer $stopword_id ID of the stop word
        *
        * @return void
        */
      public function remove($stopword_id)
      {
           $delete = sprintf(quot;DELETE FROM $this->tablename WHERE id = %d AND lang =
  '%s'quot;, $stopword_id, $this->language);

          $this->db->query($delete);
      }




                                                                            Mayflower GmbH 2009   22
Restructuring
   /**
     * Remove a word from the stop word dictionary
     *
     * @param integer $stopword_id ID of the stop word
     *
     * @return void
     */
   public function remove($stopword_id)
   {
        $delete = sprintf(quot;DELETE FROM %s WHERE id = %d AND lang = '%s'quot;,
            $this->tablename,
            $stopword_id,
            $this->language);

       $this->db->query($delete);
   }




                                                                            Mayflower GmbH 2009   23
Extraction
   /**
     * Remove a word from the stop word dictionary
     *
     * @param integer $stopword_id ID of the stop word
     *
     * @return void
     */
   public function remove($stopword_id)
   {
        $delete = sprintf(quot;DELETE FROM %s WHERE id = %d AND lang = '%s'quot;,
            $this->tablename,
            $stopword_id,
            $this->language);

       $this->db->query($delete);
   }




                                                                            Mayflower GmbH 2009   24
Extraction


   public function remove($stopword_id)
   {
       $delete = sprintf(quot;DELETE FROM %s WHERE id = %d AND lang = '%s'quot;,
           $this->tablename,
           $stopword_id,
           $this->language);

       $this->_execute($delete);
   }

   private function _execute($query)
   {
       return $this->db->query($query)
   }




                                                                           Mayflower GmbH 2009   25
Changing signature
   /**
     * Remove a word from the stop word dictionary
     *
     * @param integer $id ID of the stop word
     *
     * @return void
     */
   public function remove($stopword_id)
   {
        $delete = sprintf(quot;DELETE FROM %s WHERE id = %d AND lang = '%s'quot;,
            $this->tablename,
            $stopword_id,
            $this->language);

       $this->db->query($delete);
   }




                                                                            Mayflower GmbH 2009   26
Changing signature
   /**
     * Remove a word from the stop word dictionary
     *
     * @param integer $stopword_id ID of the stop word
     * @param boolean $logging     Log removal? Default: false
     *
     * @return void
     */
   public function remove($stopword_id, $logging = false)
   {
        $delete = sprintf(quot;DELETE FROM %s WHERE id = %d AND lang = '%s'quot;,
            $this->tablename,
            $stopword_id,
            $this->language);

       if ($logging) {
           $this->_logAction('removal', $stopword_id);
       }

       $this->db->query($delete);
   }

                                                                            Mayflower GmbH 2009   27
Pull up / Pull down




            x



                      Mayflower GmbH 2009   28
Pull up / Pull down




            x



                      Mayflower GmbH 2009   29
Pull up / Pull down




           x


       x       x



                      Mayflower GmbH 2009   30
Tips & Tricks
• Always add PHPDoc if it‘s missing
• Never trust automatic refactoring of IDEs
• Don‘t do refactoring for fun
• Write as much unittests as possible




                                              Mayflower GmbH 2009   31
Any questions?   Mayflower GmbH 2009   32
Thank you very much for your attention!



  Thorsten Rinne
  Mayflower GmbH
  Mannhardtstraße 6
  D-80538 München
  +49 (0) 89 24 20 54 - 31
  thorsten.rinne@mayflower.de

                                     Mayflower GmbH 2009   33

Contenu connexe

Similaire à Professional Refactoring

Joomla Template Development
Joomla Template DevelopmentJoomla Template Development
Joomla Template DevelopmentLinda Coonen
 
Samuel Asher Rivello - PureMVC Hands On Part 2
Samuel Asher Rivello - PureMVC Hands On Part 2Samuel Asher Rivello - PureMVC Hands On Part 2
Samuel Asher Rivello - PureMVC Hands On Part 2360|Conferences
 
Things to consider for testable Code
Things to consider for testable CodeThings to consider for testable Code
Things to consider for testable CodeFrank Kleine
 
A Z Introduction To Ruby On Rails
A Z Introduction To Ruby On RailsA Z Introduction To Ruby On Rails
A Z Introduction To Ruby On Railsrailsconf
 
Automation Solutions PowerPoint Presentation Slides
Automation Solutions PowerPoint Presentation SlidesAutomation Solutions PowerPoint Presentation Slides
Automation Solutions PowerPoint Presentation SlidesSlideTeam
 
Intro To Django
Intro To DjangoIntro To Django
Intro To DjangoUdi Bauman
 
Practical Groovy Domain-Specific Languages
Practical Groovy Domain-Specific LanguagesPractical Groovy Domain-Specific Languages
Practical Groovy Domain-Specific LanguagesGuillaume Laforge
 
Leveraging Continuous Integration For Fun And Profit!
Leveraging Continuous Integration For Fun And Profit!Leveraging Continuous Integration For Fun And Profit!
Leveraging Continuous Integration For Fun And Profit!Jess Chadwick
 
The Dojo Build System
The Dojo Build SystemThe Dojo Build System
The Dojo Build Systemklipstein
 
Bti1022 lab sheet 3
Bti1022 lab sheet 3Bti1022 lab sheet 3
Bti1022 lab sheet 3alish sha
 
Mastering Form Rules and Formulas in QuickBase
Mastering Form Rules and Formulas in QuickBaseMastering Form Rules and Formulas in QuickBase
Mastering Form Rules and Formulas in QuickBaseQuickBase, Inc.
 
AngularJS in practice
AngularJS in practiceAngularJS in practice
AngularJS in practicejhoguet
 
Hacking Movable Type Training - Day 1
Hacking Movable Type Training - Day 1Hacking Movable Type Training - Day 1
Hacking Movable Type Training - Day 1Byrne Reese
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkDirk Haun
 

Similaire à Professional Refactoring (20)

Joomla Template Development
Joomla Template DevelopmentJoomla Template Development
Joomla Template Development
 
Samuel Asher Rivello - PureMVC Hands On Part 2
Samuel Asher Rivello - PureMVC Hands On Part 2Samuel Asher Rivello - PureMVC Hands On Part 2
Samuel Asher Rivello - PureMVC Hands On Part 2
 
Things to consider for testable Code
Things to consider for testable CodeThings to consider for testable Code
Things to consider for testable Code
 
A Z Introduction To Ruby On Rails
A Z Introduction To Ruby On RailsA Z Introduction To Ruby On Rails
A Z Introduction To Ruby On Rails
 
A-Z Intro To Rails
A-Z Intro To RailsA-Z Intro To Rails
A-Z Intro To Rails
 
Automation Solutions PowerPoint Presentation Slides
Automation Solutions PowerPoint Presentation SlidesAutomation Solutions PowerPoint Presentation Slides
Automation Solutions PowerPoint Presentation Slides
 
Intro To Django
Intro To DjangoIntro To Django
Intro To Django
 
Practical Groovy Domain-Specific Languages
Practical Groovy Domain-Specific LanguagesPractical Groovy Domain-Specific Languages
Practical Groovy Domain-Specific Languages
 
Gae
GaeGae
Gae
 
Leveraging Continuous Integration For Fun And Profit!
Leveraging Continuous Integration For Fun And Profit!Leveraging Continuous Integration For Fun And Profit!
Leveraging Continuous Integration For Fun And Profit!
 
The Dojo Build System
The Dojo Build SystemThe Dojo Build System
The Dojo Build System
 
Bti1022 lab sheet 3
Bti1022 lab sheet 3Bti1022 lab sheet 3
Bti1022 lab sheet 3
 
How to build the Web
How to build the WebHow to build the Web
How to build the Web
 
FuzzyDebugger.pdf
FuzzyDebugger.pdfFuzzyDebugger.pdf
FuzzyDebugger.pdf
 
Mastering Form Rules and Formulas in QuickBase
Mastering Form Rules and Formulas in QuickBaseMastering Form Rules and Formulas in QuickBase
Mastering Form Rules and Formulas in QuickBase
 
Satchmo
SatchmoSatchmo
Satchmo
 
AngularJS in practice
AngularJS in practiceAngularJS in practice
AngularJS in practice
 
Hacking Movable Type Training - Day 1
Hacking Movable Type Training - Day 1Hacking Movable Type Training - Day 1
Hacking Movable Type Training - Day 1
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
Happy Coding with Ruby on Rails
Happy Coding with Ruby on RailsHappy Coding with Ruby on Rails
Happy Coding with Ruby on Rails
 

Plus de Mayflower GmbH

Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...
Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...
Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...Mayflower GmbH
 
JavaScript Days 2015: Security
JavaScript Days 2015: SecurityJavaScript Days 2015: Security
JavaScript Days 2015: SecurityMayflower GmbH
 
Vom Entwickler zur Führungskraft
Vom Entwickler zur FührungskraftVom Entwickler zur Führungskraft
Vom Entwickler zur FührungskraftMayflower GmbH
 
Salt and pepper — native code in the browser Browser using Google native Client
Salt and pepper — native code in the browser Browser using Google native ClientSalt and pepper — native code in the browser Browser using Google native Client
Salt and pepper — native code in the browser Browser using Google native ClientMayflower GmbH
 
Plugging holes — javascript memory leak debugging
Plugging holes — javascript memory leak debuggingPlugging holes — javascript memory leak debugging
Plugging holes — javascript memory leak debuggingMayflower GmbH
 
50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...
50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...
50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...Mayflower GmbH
 
Native Cross-Platform-Apps mit Titanium Mobile und Alloy
Native Cross-Platform-Apps mit Titanium Mobile und AlloyNative Cross-Platform-Apps mit Titanium Mobile und Alloy
Native Cross-Platform-Apps mit Titanium Mobile und AlloyMayflower GmbH
 
Pair Programming Mythbusters
Pair Programming MythbustersPair Programming Mythbusters
Pair Programming MythbustersMayflower GmbH
 
Shoeism - Frau im Glück
Shoeism - Frau im GlückShoeism - Frau im Glück
Shoeism - Frau im GlückMayflower GmbH
 
Bessere Software schneller liefern
Bessere Software schneller liefernBessere Software schneller liefern
Bessere Software schneller liefernMayflower GmbH
 
Von 0 auf 100 in 2 Sprints
Von 0 auf 100 in 2 SprintsVon 0 auf 100 in 2 Sprints
Von 0 auf 100 in 2 SprintsMayflower GmbH
 
Piwik anpassen und skalieren
Piwik anpassen und skalierenPiwik anpassen und skalieren
Piwik anpassen und skalierenMayflower GmbH
 
Agilitaet im E-Commerce - E-Commerce Breakfast
Agilitaet im E-Commerce - E-Commerce BreakfastAgilitaet im E-Commerce - E-Commerce Breakfast
Agilitaet im E-Commerce - E-Commerce BreakfastMayflower GmbH
 

Plus de Mayflower GmbH (20)

Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...
Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...
Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...
 
Why and what is go
Why and what is goWhy and what is go
Why and what is go
 
Agile Anti-Patterns
Agile Anti-PatternsAgile Anti-Patterns
Agile Anti-Patterns
 
JavaScript Days 2015: Security
JavaScript Days 2015: SecurityJavaScript Days 2015: Security
JavaScript Days 2015: Security
 
Vom Entwickler zur Führungskraft
Vom Entwickler zur FührungskraftVom Entwickler zur Führungskraft
Vom Entwickler zur Führungskraft
 
Produktive teams
Produktive teamsProduktive teams
Produktive teams
 
Salt and pepper — native code in the browser Browser using Google native Client
Salt and pepper — native code in the browser Browser using Google native ClientSalt and pepper — native code in the browser Browser using Google native Client
Salt and pepper — native code in the browser Browser using Google native Client
 
Plugging holes — javascript memory leak debugging
Plugging holes — javascript memory leak debuggingPlugging holes — javascript memory leak debugging
Plugging holes — javascript memory leak debugging
 
Usability im web
Usability im webUsability im web
Usability im web
 
Rewrites überleben
Rewrites überlebenRewrites überleben
Rewrites überleben
 
JavaScript Security
JavaScript SecurityJavaScript Security
JavaScript Security
 
50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...
50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...
50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...
 
Responsive Webdesign
Responsive WebdesignResponsive Webdesign
Responsive Webdesign
 
Native Cross-Platform-Apps mit Titanium Mobile und Alloy
Native Cross-Platform-Apps mit Titanium Mobile und AlloyNative Cross-Platform-Apps mit Titanium Mobile und Alloy
Native Cross-Platform-Apps mit Titanium Mobile und Alloy
 
Pair Programming Mythbusters
Pair Programming MythbustersPair Programming Mythbusters
Pair Programming Mythbusters
 
Shoeism - Frau im Glück
Shoeism - Frau im GlückShoeism - Frau im Glück
Shoeism - Frau im Glück
 
Bessere Software schneller liefern
Bessere Software schneller liefernBessere Software schneller liefern
Bessere Software schneller liefern
 
Von 0 auf 100 in 2 Sprints
Von 0 auf 100 in 2 SprintsVon 0 auf 100 in 2 Sprints
Von 0 auf 100 in 2 Sprints
 
Piwik anpassen und skalieren
Piwik anpassen und skalierenPiwik anpassen und skalieren
Piwik anpassen und skalieren
 
Agilitaet im E-Commerce - E-Commerce Breakfast
Agilitaet im E-Commerce - E-Commerce BreakfastAgilitaet im E-Commerce - E-Commerce Breakfast
Agilitaet im E-Commerce - E-Commerce Breakfast
 

Dernier

A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMANIlamathiKannappan
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityEric T. Tung
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...Aggregage
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMRavindra Nath Shukla
 
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...lizamodels9
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...Paul Menig
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756dollysharma2066
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesDipal Arora
 
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...Any kyc Account
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Dipal Arora
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdfRenandantas16
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxWorkforce Group
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.Aaiza Hassan
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Neil Kimberley
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Roland Driesen
 
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Delhi Call girls
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communicationskarancommunications
 
John Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfJohn Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfAmzadHosen3
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear RegressionRavindra Nath Shukla
 
Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...Roland Driesen
 

Dernier (20)

A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMAN
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSM
 
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
 
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptx
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...
 
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communications
 
John Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfJohn Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdf
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear Regression
 
Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...
 

Professional Refactoring

  • 1. Professional Refactoring International PHP Conference 2009 Spring Edition Mayflower GmbH 2009 1
  • 2. • Senior Developer / Team Lead at Mayflower GmbH • Reporting and Rating Apps • QA and PHP 5 Migration consultings • PHP since 1999 (3.0.16) • phpMyFAQ since 2001 Mayflower GmbH 2009 2
  • 3. Who are you? • What are you doing? • What‘s your team size? • Using MVC? • Who‘s using Continous Integration? • PHPUnit? • 80% code coverage? Mayflower GmbH 2009 3
  • 4. Your projects... • What‘s your average project lifetime? • Is there PHP code more than 5 years old? • How many lines of code? • How many change requests per year? • Has there been a specification? • Were all features in the first release as specified? Mayflower GmbH 2009 4
  • 5. What is Refactoring? „Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.“ -Martin Fowler, www.refactoring.com Mayflower GmbH 2009 5
  • 6. Why especially PHP? (c) www.medrehab.com Code Aging! Mayflower GmbH 2009 6
  • 7. A PHP Project in 2000 ... • no coding standards, no PHPDoc • no MVC, no Design Patterns • if you were lucky, someone used a template system • nobody cared about XSS or CSRF a lot of changes in business logics • never got refactored, documentated or even tested ... Mayflower GmbH 2009 7
  • 8. ... because it worked! Mayflower GmbH 2009 8
  • 9. In the year 2009 • change requests get more and more expensive • the bug rate is always increasing • the development team motivation is decreasing • requirement changes are almost impossible • new team members need a lot of time to be productive Mayflower GmbH 2009 9
  • 10. Management point of view Costs per Change Request rising frequency Dead end! Benefit per Change Request Mayflower GmbH 2009 10
  • 11. Start refactoring now! Mayflower GmbH 2009 11
  • 12. But hey, stop! Mayflower GmbH 2009 12
  • 13. Don‘t refactor ... • weeks before a important release • only with a lot of junior developers • parallel with development tasks Mayflower GmbH 2009 13
  • 14. Before starting refactoring • define a coding standard • avoids spaghetti code • speeds up maintainability • improves productivity • fix your API specs • complete your documentation Mayflower GmbH 2009 14
  • 15. During the refactoring... • stay calm • take a lot of good developers and a bunch of juniors • write tests, tests, tests • don‘t let developer refactor their own code • don‘t let junior developers refactor alone Mayflower GmbH 2009 15
  • 16. About Unittests • Testing is essential during refactoring • Problems • most of old code isn‘t „unittestable“ • API breaks during refacotoring • Solution • Selenium tests instead • iterative refactoring Mayflower GmbH 2009 16
  • 17. (c) BMW AG Okay, let‘s start! Mayflower GmbH 2009 17
  • 18. Back to Martin Fowler „Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.“ -Martin Fowler, www.refactoring.com Mayflower GmbH 2009 18
  • 19. Forms of refactoring •Renaming •Extraction •Changing signature •Pull up / Pull down Mayflower GmbH 2009 19
  • 20. Renaming /** * Remove a word from the stop word dictionary * * @param integer $id * * @return void */ public function remove($id) { $sql = sprintf(quot;DELETE FROM $this->tablename WHERE id = %d AND lang = '%s'quot;, $id, $this->language); $this->db->query($sql); } Mayflower GmbH 2009 20
  • 21. Renaming /** * Remove a word from the stop word dictionary * * @param integer $stopword_id ID of the stop word * * @return void */ public function remove($stopword_id) { $delete = sprintf(quot;DELETE FROM $this->tablename WHERE id = %d AND lang = '%s'quot;, $stopword_id, $this->language); $this->db->query($delete); } Mayflower GmbH 2009 21
  • 22. Restructuring /** * Remove a word from the stop word dictionary * * @param integer $stopword_id ID of the stop word * * @return void */ public function remove($stopword_id) { $delete = sprintf(quot;DELETE FROM $this->tablename WHERE id = %d AND lang = '%s'quot;, $stopword_id, $this->language); $this->db->query($delete); } Mayflower GmbH 2009 22
  • 23. Restructuring /** * Remove a word from the stop word dictionary * * @param integer $stopword_id ID of the stop word * * @return void */ public function remove($stopword_id) { $delete = sprintf(quot;DELETE FROM %s WHERE id = %d AND lang = '%s'quot;, $this->tablename, $stopword_id, $this->language); $this->db->query($delete); } Mayflower GmbH 2009 23
  • 24. Extraction /** * Remove a word from the stop word dictionary * * @param integer $stopword_id ID of the stop word * * @return void */ public function remove($stopword_id) { $delete = sprintf(quot;DELETE FROM %s WHERE id = %d AND lang = '%s'quot;, $this->tablename, $stopword_id, $this->language); $this->db->query($delete); } Mayflower GmbH 2009 24
  • 25. Extraction public function remove($stopword_id) { $delete = sprintf(quot;DELETE FROM %s WHERE id = %d AND lang = '%s'quot;, $this->tablename, $stopword_id, $this->language); $this->_execute($delete); } private function _execute($query) { return $this->db->query($query) } Mayflower GmbH 2009 25
  • 26. Changing signature /** * Remove a word from the stop word dictionary * * @param integer $id ID of the stop word * * @return void */ public function remove($stopword_id) { $delete = sprintf(quot;DELETE FROM %s WHERE id = %d AND lang = '%s'quot;, $this->tablename, $stopword_id, $this->language); $this->db->query($delete); } Mayflower GmbH 2009 26
  • 27. Changing signature /** * Remove a word from the stop word dictionary * * @param integer $stopword_id ID of the stop word * @param boolean $logging Log removal? Default: false * * @return void */ public function remove($stopword_id, $logging = false) { $delete = sprintf(quot;DELETE FROM %s WHERE id = %d AND lang = '%s'quot;, $this->tablename, $stopword_id, $this->language); if ($logging) { $this->_logAction('removal', $stopword_id); } $this->db->query($delete); } Mayflower GmbH 2009 27
  • 28. Pull up / Pull down x Mayflower GmbH 2009 28
  • 29. Pull up / Pull down x Mayflower GmbH 2009 29
  • 30. Pull up / Pull down x x x Mayflower GmbH 2009 30
  • 31. Tips & Tricks • Always add PHPDoc if it‘s missing • Never trust automatic refactoring of IDEs • Don‘t do refactoring for fun • Write as much unittests as possible Mayflower GmbH 2009 31
  • 32. Any questions? Mayflower GmbH 2009 32
  • 33. Thank you very much for your attention! Thorsten Rinne Mayflower GmbH Mannhardtstraße 6 D-80538 München +49 (0) 89 24 20 54 - 31 thorsten.rinne@mayflower.de Mayflower GmbH 2009 33