Code Smells

It’s useful to have a vocabulary for talking about refactoring. It will help you to communicate when doing strong-style pairing or mob programming. Code smells is perhaps a less-known concept than refactoring and knowing these names will also help you to communicate about code. In this learning hour we’ll talk about what a code smell is and learn the names of a few of them.

Session Outline

How do you know when to refactor?

What kind of characteristics of the code prompt you to for example:

Note down your ideas and share them with the group when the facilitator asks.

Code smells

Explain Martin Fowler’s description of code smells. Note that the names of these are in his book but not on his website. For a list of some common code smell names seen wikipedia

Find code smells

Have them review all 3 of the Tennis implementations in The Tennis Refactoring Kata, and note down any code smells they find. The idea is just to read the code at this point, not change it.

When they’ve looked at the code, write up on a whiteboard the names of smells that they have found. Tell them the ‘official’ name (from Fowler’s book) if they don’t know it.

Address a code smells

Pick one of the smells and look up the corresponding refactoring. Depending on the skill of the group, either demo the refactoring or ask them to do it. Repeat with more smells and refactorings.

Define ‘Code smell’

How would you define ‘code smell’? Write a definition on a sticky note and take it with you to put next to your screen.