Slide 1

Slide 1 text

Workshop Setup Navigate to https://github.com/CodingZeal/gilded-rose-railsconf2015 Click on the Nitrous QuickStart button Create a new account or Log in to your existing account

Slide 2

Slide 2 text

www .codingzeal.com @codingzeal Randy Coulman a.k.a. Refactron Refactoring When You Literally Can’t Even Senior Software Engineer @randycoulman

Slide 3

Slide 3 text

Welcome to our new job! Enhance the inventory management system for the Gilded Rose Inn

Slide 4

Slide 4 text

The System • Sell_in: the number of days we have to sell the item • Quality: how valuable the item is • End of each day: lower both values for every item

Slide 5

Slide 5 text

The Spec: Can We Trust It? • Once the sell-by date has passed, quality degrades twice as fast • The quality of an item is never negative • “Aged Brie" actually increases in quality the older it gets • The quality of an item is never more than 50 • "Sulfuras", being a legendary item, never has to be sold or decreases in quality • "Backstage passes", like aged brie, increases in quality as its sell-by date approaches; quality increases by 2 when there are 10 days or less and by 3 when there are 5 days or less, but quality drops to 0 after the concert.

Slide 6

Slide 6 text

Constraint The Item class and @items property are off-limits No collective code ownership

Slide 7

Slide 7 text

Our Task: Support Conjured items Conjured items degrade in quality twice as fast as normal items

Slide 8

Slide 8 text

Workshop Structure Mix of: • Presentation • Mob programming • Small group/pair/individual work

Slide 9

Slide 9 text

Mob Programming • One computer for programming • One driver • N navigators and researchers http://mobprogramming.org/mob-programming-basics/

Slide 10

Slide 10 text

How to Change Code https://twitter.com/KentBeck/status/250733358307500032

Slide 11

Slide 11 text

What is Refactoring? “a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior” http://refactoring.com

Slide 12

Slide 12 text

Refactoring

Slide 13

Slide 13 text

Refactoring Many refactorings are mechanical

Slide 14

Slide 14 text

When to Refactor? Get legacy code under control

Slide 15

Slide 15 text

When to Refactor? An ongoing part of your workflow Test-Driven Development (TDD) Cycle: Red -> Green -> Refactor

Slide 16

Slide 16 text

Why Refactor? Make the code reflect your current understanding of the system

Slide 17

Slide 17 text

Why Refactor? Ideal: Make the code look like it would have looked if the feature you just added had always been there

Slide 18

Slide 18 text

Refactoring Requires test coverage

Slide 19

Slide 19 text

Refactoring Legacy Code The Scouting Rule: "Leave the campground cleaner than you found it"

Slide 20

Slide 20 text

Refactoring Legacy Code Baby Steps Lots of tiny, safe refactorings add up to big changes

Slide 21

Slide 21 text

Refactoring Legacy Code Don’t Boil the Ocean Stay focused on your task

Slide 22

Slide 22 text

Refactoring Legacy Code https://twitter.com/supermoof/status/478322429257715712

Slide 23

Slide 23 text

The Code

Slide 24

Slide 24 text

Want More? Original Gilded Rose Kata http://craftsmanship.sv.cmu.edu/katas/gilded-rose-kata Gilding the Rose Talk at GoGaRuCo 2014 http://confreaks.tv/videos/gogaruco2014-gilding-the-rose-refactoring-legacy-code Code from GoGaRuCo 2014 Talk https://github.com/randycoulman/GildedRose

Slide 25

Slide 25 text

References Working Effectively With Legacy Code: Michael Feathers http://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052 Refactoring: Martin Fowler http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672 Refactoring Ruby Edition: Jay Fields, Shane Harvie, and Martin Fowler http://www.amazon.com/Refactoring-Ruby-Jay-Fields/dp/0321603508

Slide 26

Slide 26 text

Questions ? http://randycoulman.com Code is on Github https://github.com/CodingZeal/gilded-rose-railsconf2015 Slides Are on Speakerdeck https://speakerdeck.com/randycoulman

Slide 27

Slide 27 text

www .codingzeal.com @codingzeal Thank You! Randy Coulman @randycoulman