
Code smells. I’ve mentioned “code smells” at work, only to discover that my coworkers didn’t know what I meant. It’s basically a diaper-changing metaphor: “If it stinks, change it.”
“If it stinks, change it.”
A code smell isn’t “awful code that makes you hold your nose.” Rather, it’s a simple indication that something may need to be changed. Quite often, you won’t notice a code smell until someone else describes it. This is what Kent Beck and Martin Fowler did in the Refactoring book: created a list of smells, and what to do about them.
Code Smells Specific to Objective-C
The book’s catalog of code smells relate to good practices of object-oriented programming. I’m going to start a series that is specific to Objective-C code smells. Here’s a tentative list to give you a preview:
- 9 Code Smells of Preprocessor Use
- #imports Gone Wild! How to Tame File Dependencies
- 4 Ways Precompiled Headers Cripple Your Code
- Dot Notation in Objective-C: 100% Pure Evil
- Don’t Message self in Objective-C init (and dealloc)
I think this’ll be interesting, and sometimes even controversial. (Dot notation, anyone?) So be sure to come back — subscribe to keep up with the latest postings!
And in the meantime, check out these related resources:
- The Refactoring Book: A Game-Changer
- Martin Fowler explains “code smell”
- Summary of code smells from the book, with the refactorings to fix them
Photo by *bethography* (license), adapted by Jon Reid






Hi Jon,
I think you’ve picked a great topic here. I know that there will be things that I will be able to learn from. I look forward to your next post.
Take care,
Cory
Thanks for the encouragement, Cory! I hope you’ll also chime in with your own code smells.
Jon,
I’m looking forward to your series. You have me curious about #4
Doug
Doug,
Calling #4 a smell may be a stretch, we’ll see…
Just after reading that “Preprocessor use” may cause code smell I became instantly intrigued. Would you mind giving me a hint of what that might be?
Eimantas, here’s a hint: THHomePriceIndex.h
Thanks for quick reply.
Regarding the CPP – that’s not “use”. That’s “abuse” .)