The Power Of Refactoring (php|tek 09)

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    3 Favorites & 2 Groups

    The Power Of Refactoring (php|tek 09) - Presentation Transcript

    1. The Power of Refactoring Stefan Koopmanschap PHP|tek, Chicago, May 22nd 2009
    2. What will we do? What is refactoring? Why refactoring? When refactoring? Requirements HOWTO 2
    3. Stefan Koopmanschap Who is he? 3
    4. About me Professional Services Consultant at Ibuildings 10 years of PHP experience PHP auto didact married, 2 kids, 6 cats, a bunch of fish Apple lover music addict symfony advocate 4
    5. Refactoring What is it? 5
    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
    10. Improve readability 10
    11. Improve maintainability 11
    12. Extend (or change) 12
    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
    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
    16. 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
    17. Requirements for successful refactoring 17
    18. Requirements Codebase knowledge Structured API Unit testing 18
    19. Codebase knowledge Know what to change quickly Be aware of your changes Be aware of impact of your changes on other components 19
    20. 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
    21. Unit testing Unit testing is your first point of QA They safeguard you from unexpected side effects Test - Change - Test 21
    22. When? Timing of refactoring 22
    23. Two moments of refactoring Big chunks Continuous refactoring 23
    24. Big Chunks As you encounter problems, you keep track • Ticketing system • TODO list • Inline comments Schedule one or more moments in your project • Work through your list • Refactor them 24
    25. Big Chunks work? Advantages • Set times for refactoring • Focus on your project when you need to • Works well for functional changes Disadvantages • Refactoring gets cancelled first with tight deadlines • You may have forgotten specific solutions already 25
    26. Continuous Refactoring Refactor while you work Encounter a problem, fix it! 26
    27. Continuous Refactoring works? Advantages • No need to schedule seperate time • Continuous improvement of your code Disadvantages • Danger of losing the balance between tasks and refactoring 27
    28. Who should refactor? 28
    29. Who should refactor? Someone with knowledge of the codebase • Or at least the part that is being refactored Not necessarily the code owner 29
    30. An example user authentication 30
    31. A test-driven approach 31
    32. My first implementation 32
    33. A more dynamic version 33
    34. Tips and tricks 34
    35. 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 35
    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 36
    37. The Power of Refactoring 37
    38. Creative Commons Rocks! Readability: http://www.flickr.com/photos/vipulmathur/ 471634239/ (by-nc-sa/2.0) Maintainability: http://www.flickr.com/photos/sveinhal/ 2416609728/ (by-nc-nd/2.0) Extend: http://www.flickr.com/photos/ 30691679@N07/2972145815/ (by-nc-sa/2.0) Holy Grail: http://www.flickr.com/photos/joebeone/ 153921142/ (by/2.0) 38
    39. Questions ? 39
    40. Thank you! Contact details: Stefan Koopmanschap http://www.leftontheweb.com/ http://www.ibuildings.com/ http://www.twitter.com/skoop http://www.slideshare.net/skoop http://joind.in/talk/view/240

    + Stefan KoopmanschapStefan Koopmanschap, 6 months ago

    custom

    795 views, 3 favs, 0 embeds more stats

    The slides for my "Power of Refactoring" talk as do more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 795
      • 795 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 3
    • Downloads 0
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Groups / Events