DEV Community


Discussion on: Explain "Code Smells" like I'm five

mellen profile image
Matt Ellen

When someone is really good at something, like a footballer (or basket ball player if you're American), what that means is that they have been in so many and varied footballing (or basket balling) situations that they have learnt how best to act in those situations. We often call that instinct, because of how fast they can apply what they have learnt.

So if a really experienced footballer looks over a field of players, they will be able to see when someone is stood in the wrong position or is making the wrong play. They might not be able to fully explain how they know, but they can feel it.

So even though nothing bad might happen because of what is going on on the field in the moment, something bad might happen later because of it, maybe the team loses possession, or a player ends up offside.

You might call that a "play smell" because the experienced player can sense something isn't right, even though nothing bad is immediately evident, like how you can smell smoke before you can see a fire.

A code smell is a lot like that. An experienced programmer can look over code, maybe even their own, and see over complexity or other inefficiencies in the making.

The code is beginning to smell.

A lot of code smells are so frequently done by less experienced or very tired programmers that the types of smell can be documented, which is why you often see blog posts about how "[this code pattern] is a code smell".