Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Refactoring Dojo and the Gilded Rose Kata @swkcgn

Refactoring Dojo and the Gilded Rose Kata @swkcgn

At the Softwerkskammer Cologne, we did the Gilded Rose Kata. As introduction to refactoring, I talked using these decks about the major principles behind refactoring.

Steve Korzinetzki

February 19, 2018
Tweet

More Decks by Steve Korzinetzki

Other Decks in Programming

Transcript

  1. Refactoring Dojo
    Gilded Rose Kata
    Steve Korzinetzki
    @SWKCGN February 2018

    View full-size slide

  2. Code Duplication Deodorant Comment Speculative Generality
    Refused Bequest Large Class Long Parameter List
    Divergent Change ShotGun Surgery Feature Envy
    Data Clumps Switch Statements Primitive Obsession
    Inappropriate Intimacy Lazy Class Temporary Field
    Message Chains Long Method Middle Man
    Parallel Inheritance Hierarchy Alternative Classes with Different Interfaces
    Conditional Complexity Combinatorial Explosion Black Sheep

    View full-size slide

  3. Code Duplication Deodorant Comment Speculative Generality
    Refused Bequest Large Class Long Parameter List
    Divergent Change ShotGun Surgery Feature Envy
    Data Clumps Switch Statements Primitive Obsession
    Inappropriate Intimacy Lazy Class Temporary Field
    Message Chains Long Method Middle Man
    Parallel Inheritance Hierarchy Alternative Classes with Different Interfaces
    Conditional Complexity Combinatorial Explosion Black Sheep

    View full-size slide

  4. Technical Debt
    Ward CunningHam
    Signee of Agile Manifesto

    View full-size slide

  5. Refactoring
    Martin Fowler
    Refactoring: Improving The Design of existing Code

    View full-size slide

  6. Catalog of Refactorings
    Composing Methods Moving Features Between Objects
    Organizing Data Simplifying Conditional Expressions
    Making Method Calls Simpler Dealing with Generalization
    Big Refactorings

    View full-size slide

  7. Catalog of Refactorings
    Composing Methods Moving Features Between Objects
    Organizing Data Simplifying Conditional Expressions
    Making Method Calls Simpler Dealing with Generalization
    Big Refactorings

    View full-size slide

  8. Example Refactoring: Decompose Conditional
    if (date.before (SUMMER_START) || date.after (SUMMER_END))
    {
    charge = quantity * _winterRate + _winterServiceCharge;
    } else {
    charge = quantity * _summerRate;
    }

    View full-size slide

  9. Example Refactoring: Decompose Conditional
    if (date.before (SUMMER_START) || date.after (SUMMER_END))
    {
    charge = quantity * _winterRate + _winterServiceCharge;
    } else {
    charge = quantity * _summerRate;
    }
    if (notSummer(date))
    {
    charge = winterCharge(quantity);
    } else {
    charge = summerCharge(quantity);
    }

    View full-size slide

  10. Refactoring Strategies
    Piecemeal Refactoring Nesting
    Parallel Change Evolved Target
    Caller Creates Graceful RetreaT
    etc...

    View full-size slide

  11. Two Hats
    adding functions
    refactoring

    View full-size slide

  12. safety net of automated tests

    View full-size slide

  13. Approval Testing
    And The Golden Master

    View full-size slide

  14. Make Baby Steps

    View full-size slide

  15. Design Patterns as Goal
    For Refactoring
    Erich Gamma
    Gang of Four

    View full-size slide

  16. Keep Solid Principles in Mind

    View full-size slide

  17. Four Rules of Simple Design
    Kent Beck
    Author of Extreme Programming

    View full-size slide

  18. Intermediate Steps
    may look worse before it‘s
    getting better

    View full-size slide

  19. Any Fool can write code,
    that a Computer understands.
    good Programmers write code,
    that humans understand.
    Martin Fowler
    Refactoring: Improving The Design of existing Code

    View full-size slide

  20. First Make the change easy,
    (Warning: this might be hard!)
    then make the easy change
    Kent Beck
    Author of Extreme Programming

    View full-size slide

  21. Photo Credits
    KRanhaus by Thorsen Hansen: https://www.flickr.com/photos/th_hansen/11151520553/
    Trash by Vladimer Shioshvili: https://www.flickr.com/photos/vshioshvili/246797594/
    Coins by Rodrigo Amorim: https://www.flickr.com/photos/zetotal/3840452595/
    USS Roosevelt (DDG 80) by U.S. Naval Forces Central Command/U.S. Fifth Fleet:
    https://www.flickr.com/photos/navcent/15068556901/
    Safety Net by Chad: https://www.flickr.com/photos/iamchadhearmesnore/3629410556/
    photograph 287 By Tianna Spicer: https://www.flickr.com/photos/tiannaspicer/8618453971/
    Learning to walk by Tela Chhe: https://www.flickr.com/photos/telachhe/3342173731/
    Stay On Target By Pete: https://www.flickr.com/photos/comedynose/7865159650/
    Adrenaline as an obsession by Erlend Aaby: https://www.flickr.com/photos/erlendaaby/8959485642/
    Referees by Ronnie Macdonald: https://www.flickr.com/photos/ronmacphotos/14871566117/
    Hopeless by Gauthier DELECROIX: https://www.flickr.com/photos/gauthierdelecroix/36059288880/
    Game Programmer at work by Sergey Galyonkin: https://www.flickr.com/photos/sergesegal/11512594484/
    Santiago Garza by Santiago Garza: https://www.flickr.com/photos/151318721@N02/34684657560/
    IMGP3193 By François MORARD: https://www.flickr.com/photos/45368675@N03/16064828445/
    Any Questions? By Nan Palmero: https://www.flickr.com/photos/nanpalmero/9370593260/
    Gold fisher by peter: https://www.flickr.com/photos/stockispicts/10982462243

    View full-size slide