Question

I am trying to understand the difference between these two terms. In some contexts that these two terms have been used interchangeably. What is the exact difference between these two terms ?

Was it helpful?

Solution

A Code Smell is something which should be investigated. Is it a piece of delicious cheese or is it rotten beef? An Anti-Pattern is just bad, a Code Smell is something which may or may not be bad.

This quote from the Wiki page is extremely relevant (the emphasis is from the original source):

Note that a CodeSmell is a hint that something might be wrong, not a certainty. A perfectly good idiom may be considered a CodeSmell because it's often misused, or because there's a simpler alternative that works in most cases. Calling something a CodeSmell is not an attack; it's simply a sign that a closer look is warranted.

An Anti-Pattern is a Pattern which, when you follow it, will lead you towards a worse design in the same way that a Pattern will lead you towards a better design:

An AntiPattern is a pattern that tells how to go from a problem to a bad solution. […] In the old days, we used to just call these 'bad ideas'. The new name is much more diplomatic.

OTHER TIPS

I'm writing my answer because I think that the two concepts can be confusing and I want to state a list of clear and direct difference.

Differences

Facts: Anti-patterns "the fact that it looks like a good solution is its essential danger" 1. On the other side, "smell is by definition something that's quick to spot" and "it's easy for inexperienced people to spot them" 2.

The gist: anti-patterns are more abstract, more subtle, more difficult to recognise. Smells are easier and quicker to see or smell.

Facts: Code smells "they are often an indicator of a problem rather than the problem themselves" and "smells don't always indicate a problem" 2

The gist: Code smells are symptoms that could hint to some more profound; anti-patterns are more profound themselves.


Footnotes:

  1. https://martinfowler.com/bliki/AntiPattern.html
  2. https://martinfowler.com/bliki/CodeSmell.html

"Code smells" are an insulting judgement of someone's code, based on blindly applying some rule without understanding it. It's a word that is used by some anti-social programmers. NEVER use this word in my presence. You will not be happy.

A "pattern" is something that many people use to solve some kind of problem. An "anti-pattern" is a pattern that doesn't work and gets you into trouble. "Pattern" is often also used to mean "a pattern that works" since things that don't work usually don't become patterns.

Licensed under: CC-BY-SA with attribution
scroll top