Replacing Conditionals with Polymorphism

Sandi Metz (

Half-day workshop - in English

Conditionals are the bane of object-oriented programming. Many times they are initially the cheapest solution but as time passes they attract friends and gradually become impossible to understand, test, reuse, or change. This workshop uses the song (99 Bottles of Beer)[ Beer] as the basis for a group refactoring which gradually replaces conditionals with simple objects. It develops a refactoring recipe that breaks the process into iterative steps. Each step ends with working code (a "landing point") and while every intermediate landing point is more complicated than the initial solution, the final result is markedly simpler. Participants will learn to confidently remove conditionals. They'll see temporary complexity pay off in ultimate simplicity and learn about the perils of abstraction and the tyranny of DRY. They'll sing while they do this, and afterwards will likely want a beer.

Primarily for:

Participant requirements: This works best if participants do the refactoring themselves, which obviously requires that they know and are set up to run Ruby on their laptops. Depending on the makeup of the class we'll use combination of pairing, small groups, and mob programming to do the exercise. If you do not have Ruby installed you'll likely be able to pair with someone who does. If you wish to install Ruby, follow (these instructions)[].