This is the companion code to my Agile Alliance Tech Conference 2017 talk. Slides for the talk can be found at http://boochtek.com/aatc2017.
Pair (or triple) up to work on the following exercises.
Don't forget to use your resources with more info on smells and refactorings:
Start with these story-splitting exercises:
- Events
- Overly detailed
- Has
When
steps afterThen
steps - Checks more than 1 thing
- Electric Car
- Not customer-focused
- Tries to do too much all at once
- Asks for the impossible
Choose from among the following exercises. There's more here than you'll have time to finish during the workshop. You might want to start out with a language that you're familiar with. Or peruse them all and see which ones interest you.
- Installations Controller (Ruby)
- Lots of duplicated code and nested conditionals
- Extracted from some actual Rails code
- There are some prewritten characterization specs if you're familiar with writing those already
- Roman Numerals (Java)
- Overly complicated code, plus overly simplistic ("shameless green") code
- From http://exercism.io/tracks/java/exercises/roman-numerals
- Roman Numerals (C#)
- Not a bad approach, but needs to be a bit more DRY
- From http://exercism.io/tracks/csharp/exercises/roman-numerals
- Bowling (Ruby)
- Inconsistent and cluttered formatting
- It looks like it has problems
- Long methods
- Probably at least 1 other class needing to be extracted
- From http://exercism.io/tracks/ruby/exercises/bowling
- Inconsistent and cluttered formatting
- Bowling (JavaScript)
- One big function
- From http://exercism.io/tracks/javascript/exercises/bowling
- Roulette (C++)
- Long functions
- Needs to extract some classes for obvious abstractions
- Lots of loops and conditionals
- From http://thedailywtf.com/articles/the-end-of-the-lucky-deuce
For a more extensive refactoring exercise, I'd recommend the Gilded Rose Kata.
It's available in several variants in several languages.
Just google for gilded rose kata
plus your programming language.
For even more refactoring exercises (in a more structured fashion), I'd recommend Refactoring Workbook by William C. Wake.
You should also check out Exercism. They've got a bunch of different exercises, and support several dozen different languages. You write your code for a given exercise, and others give you feedback on how to improve it. It's free to use; just sign in with your GitHub account. You will need to install a command-line program to make submissions.