Quality Coding

Code Smells in Objective-C

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.”

Code Smells

diaper” by beth darbyshire, used under CC BY-NC-ND 2.0 / added text

“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:

  1. 9 Code Smells of the Preprocessor (and Their Fixes)
  2. #imports Gone Wild! How to Tame File Dependencies
  3. 4 Ways Precompiled Headers Cripple Your Code
  4. Is Dot Notation in Objective-C 100% Pure Evil?
    …or maybe not! I switched, see In Which I Embrace Dot Notation…
  5. Objective-C init: Why It’s Helpful to Avoid Messages to self

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!

Other resources:

Question: What common Objective-C practices have you encountered that you might consider code smells? Leave a comment below.

About the Author Jon Reid

Jon is a coach and consultant on iOS Clean Code (Test Driven Development, unit testing, refactoring, design). He’s been practicing TDD since 2001. You can learn more about his background, or see what services he can bring to your organization.

follow me on:
Disclosure: The book links below are affiliate links. If you buy anything, I earn a commission, at no extra cost to you.

Leave a Comment:

Cory Wheeler says 6 years ago

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,

    Jon Reid says 6 years ago

    Thanks for the encouragement, Cory! I hope you’ll also chime in with your own code smells.

Doug Sjoquist says 6 years ago

I’m looking forward to your series. You have me curious about #4 :-)

    Jon Reid says 6 years ago

    Calling #4 a smell may be a stretch, we’ll see… :)

Eimantas says 6 years ago

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?

Mayur says 3 years ago

Hi Jon,
Great topic!!.
Looking forward to your next post. – Mayur

Add Your Reply