views:

154

answers:

2

I realise this could be "very subjective", but I have asked different people from many work places who are used to different languages and ideologies what a code smell is, and noone can agree what a code smell is. It would be good to get a definition that most people can agree on.

For example, what one developer calls a code smell, another developer calls a "super feature" of their language/framework.

And yes, I have seen:

http://stackoverflow.com/questions/114342/what-are-code-smells-what-is-the-best-way-to-correct-them

The code smells defined by wikipedia have many cases where they are not applicable:

  • Duplicate code: identical or very similar code exists in more than one location - sometimes this is a good thing, as you may have processes which are known will diverge slightly. Or for readabilities sake it is often better. Or when you first duplicate code you may cut and paste it as you don't know if you want to keep the second copy yet

  • Large method: a method, function, or procedure that has grown too large. Sometimes large methods are perfect for tasks and very readable

  • Large class: a class that has grown too large, see God object. Sometimes classes have alot of responsibility and become large. Why is this bad?

  • Feature envy: a class that uses methods of another class excessively. I use String classes alot in Java. Does this make String of StringBuffer bad?

  • Inappropriate intimacy: a class that has dependencies on implementation details of another class. Examples anyone, maybe this one is good

  • Refused bequest: a class that overrides a method of a base class in such a way that the contract of the base class is not honored by derived class. See Liskov substitution principle. Fair enough

  • Lazy class: a class that does too little. What, first too much code, now we get penalised for writing too little!

  • Duplicated method: a method, function, or procedure that is very similar to another. Sometimes things do slightly different things

  • Contrived Complexity: forced usage of overly complicated design patterns where simpler design would suffice. Depends who judges what is complex. Sounds like architecture astronauts looking at a system and saying it is too complicated as they don't understand the business domain or the application. But still, can be true too!

+2  A: 

How about the Wikipedia defnition of Code Smell?

In computer programming, code smell is any symptom in the source code of a program that possibly indicates a deeper problem.

marklai
Ok, but it is not enough. Is adding "will often vary by language, developer and development methodology" enough to make it a complete definition. Or just too vague?
Zubair
Arnis L.
+1  A: 

A code smell is a hint that something has gone wrong somewhere in your code.

If something smells, it definitely needs to be checked out, but it may not actually need fixing or might have to just be tolerated.

(All emphasis were mine) Source

It would be good to get a definition that most people can agree on.

I already agree with the definition above. In the end, it's just good sense in your development based on experience from a lot of work, from a lot people, in real world scenarios, of what should be avoided when coding.

How do you create a rational and accepted definition of "good sense"? A "God Class" is a code smell, but in a different context (like a great backup script you made to accomplish some needs on your home machine), it doesn't need to be "fixed".

But it's still a smell.

(And for the points you made about code smells read the link I provided)

GmonC
Thankyou. A very sensible answer. Yes, I guess alot of code smells are tolerated, and do not need to be fixed.
Zubair