views:

207

answers:

6

In my mind I think that an anti-pattern is the cause, and a code-smell is just one of man possible symptons. Is this correct?

For example:

  • God class antipattern -> large class code smell

  • Not Invented Here Antipattern -> code that should not even be there

  • Analysis Paralysis anti-pattern -> no code smell results, but leads to bankcruptcy or something else

So, what I am saying is that maybe code-smells are just one of many possible symptons of an anti-pattern, or "bad practice".

+6  A: 

It's the same relationship between good style and patterns.

A code smell is just that you've got some bad things in your code.

An anti-pattern is the description of a common source of bad things in your code.

Joachim Sauer
This is just wrong. The whole point of the "Smell" metaphor is that a smell is *not* something bad. It is something *interesting* that needs to be investigated to figure out whether it is a gas leak (bad) or a beautiful piece of spanish goat cheese (good).
Jörg W Mittag
And code with "good style" can be a bad sign, when it's applied wrong or the "good style" is implemented for its own sake. In some situations the use of an anti-pattern could arguably be appropriate and the use of a specific established pattern could be a bad idea.
Joachim Sauer
+1  A: 

Excessive use of anti-pattern will be code smell.

fastcodejava
Could you explain some more?
Zubair
+2  A: 

Maybe antipatterns are bad ideas put into code, while code smells result from having no ideas.

A bad idea, even if carried through with elegant precision would be an antipattern.

I find that code smells often emanate when I don't know how to solve a specific problem in a clear and concise way. Let's say a new function has to be introduced in an exising program, but the architecture of the program doesn't really support the new function. Maybe the new function could be easily implemented if you added a magic widget to every form, and 200 almost identical lines to most of your business classes and a new field to half of your data tables. You know it would work this way, but solving it that way would be SMELLY.

If, however, you got the right idea you could implement the new function in a new layer of your architecture to support the new function without introducing any new smells.

Guge
I don't understand?
Zubair
I added some clarification. Hope it helps.
Guge
yes, much clearer now,thanks
Zubair
A: 

A code smell COULD be an indication of an Anti-Pattern (but doesn't necessarily has to).

Helper Method
Can you give an example?
Zubair
A lot of static methods could indicate a lack of understanding of OOD and thus result procedural code (in an object oriented language). On the other hand, it could just be a class with helper functions (like java.util.Arrays), which is fine.
Helper Method
So basically yes, it's a symptom.
Helper Method
+3  A: 

An anti-pattern is almost always a bad thing. It's a concrete 'badness' that you can detect.

Code smells were named so because they're like a bad smell in the fridge. Something's probably wrong, but it may not be immediately apparent what the problem is. And sometimes, the food's actually supposed to smell that way.

Anti-patterns should be removed. A code smell is a sign that more investigation is warranted, and may reveal an anti-pattern.

kyoryu
A: 

An Anti Pattern:

  • is a Design Pattern used in the wrong context
  • "is something that looks like a good idea, but which backfires badly when applied" (James O. Coplin)
  • tells you how to go from a problem to a bad solution
Helper Method