What are Code Smells? What is the best way to correct them?
- by Rob Cooper
OK, so I know what a code smell is, and the Wikipedia Article is pretty clear in its definition:
In computer programming, code smell is
any symptom in the source code of a
computer program that indicates
something may be wrong. It generally
indicates that the code should be
refactored or the overall design
should be reexamined. The term appears
to have been coined by Kent Beck on
WardsWiki. Usage of the term increased
after it was featured in Refactoring.
Improving the Design of Existing Code.
I know it also provides a list of common code smells. But I thought it would be great if we could get clear list of not only what code smells there are, but also how to correct them.
Some Rules
Now, this is going to be a little subjective in that there are differences to languages, programming style etc. So lets lay down some ground rules:
** ONE SMELL PER ANSWER PLEASE! & ADVISE ON HOW TO CORRECT! **
See this answer for a good display of what this thread should be!
DO NOT downmod if a smell doesn't apply to your language or development methodology
We are all different.
DO NOT just quickly smash in as many as you can think of
Think about the smells you want to list and get a good idea down on how to work around.
DO downmod answers that just look rushed
For example "dupe code - remove dupe code". Let's makes it useful (e.g. Duplicate Code - Refactor into separate methods or even classes, use these links for help on these common.. etc. etc.).
DO upmod answers that you would add yourself
If you wish to expand, then answer with your thoughts linking to the original answer (if it's detailed) or comment if its a minor point.
DO format your answers!
Help others to be able to read it, use code snippets, headings and markup to make key points stand out!