Imagine that you reach into the back of the fridge and you find some food that looks appetizing, but you’re not sure how long it’s been back there. Is it still ok to eat? So you give it sniff; does it smell ok?
This is the idea when we talk about code smells. These are situations that might turn out to be ok, but that fail the initial sniff test. They seem a little “off” so we need to take a deeper look before we decide that it’s ok to keep them.
An example of a code smell might be a very long method. It’s not necessarily a problem but does warrant a closer look. Does it really need to be this long? Would it be more maintainable if it was broken into smaller methods? Often the answer is yes, but it isn’t guaranteed to be yes. This is a smell; a warning that we should take a closer look.
We often talk about smells as if they were always a problem and that’s very misleading. Smells are feedback to us that we might have a problem, not that we absolutely do.