There are a lot of fun terms, like “code smells,” that come up in programming. And though they may have unusual names and make somewhat tedious or boring concepts sound a little more exciting, they can often refer to something that decreases the quality of what we’re building.

At least, that’s the case with code smells.

In a previous post, I’ve talked about using PHP CodeSniffer to watch the code we’re writing to help us make sure that we’re following certain standards, rules, and what not but I’ve not discussed it regarding code smells.

Code Smells Defined

In a recent article for Envato, I do just that.

Understanding Code Smells

A good, working definition of a code smell is as follows:

Code smell, also known as a bad smell, in computer programming code, refers to any symptom in the source code of a program that possibly indicates a deeper problem.

And with that as the foundation of the term, I give several examples of what code smells look like and how we can identify them.

In the article, I look at the following topics:

  1. Clear Naming Conventions
  2. Staying DRY (or avoiding repeating ourselves)
  3. Long Parameter Lists

For each of the aforementioned topics, I also provide an example of how to resolve the smell through refactoring. Ultimately, the goal is to make the code less, ahem, smelly. But it’s also to show how we can write better code in a more general sense to avoid such common mistakes.

The rest of the article prepares a segue into how we can get started using PHP CodeSniffer and then how we can hook in the WordPress Coding Standards.

Some of this will be a refresher for those of you who have followed past articles. Others may find it an improvement over previous articles as the series is geared towards those who have absolutely no experience with code smells and related topics nor have any idea how to get started with code sniffers and other related software.

So if you’re someone who isn’t familiar with any of the topics above or are looking for a refresher, then check out the article.

Feel free to leave any questions in the comment feed, as well.