Can you explain the concept of a "code smell" in an approachable way?
For further actions, you may consider blocking this person and/or reporting abuse
Can you explain the concept of a "code smell" in an approachable way?
For further actions, you may consider blocking this person and/or reporting abuse
Latest comments (17)
code smell: code that seems to be working perfect, but hides a problem that can occur in the future
When somebody thinks this is a bad code, but can't explain why
Code is said to "smell" when it doesn't follow best practices, isn't idiomatic (not standard), or is likely to be error prone.
To me, it's a lazy (and often condescending) way to describe issues in a code. "That has a bad smell." Well, why? Elaborate.
Sometimes it means an intuition that something can be improved, but the reviewer lacks the vocabulary to say why or how.
For example if you have code that is supposed to determine the state of a button based on user interaction, and it's 500 lines of code, something is definitely wrong there, that code is going to "smell". An experienced engineer might recommend better design patterns, give ideas how to reduce the complexity, illuminate a path towards something more elegant, maintainable, and most importantly, stable.
yes
Here you have 56. Choose your weapon
Code Smell 53 - Explicit Iteration
Maxi Contieri ・ Jan 5 ・ 1 min read
dev.to/mcsee/series/9470
Code did a poo poo
When you’ve spent a lot of time making things, for example, Lego constructions you’ll begin to see things that while they work, they aren’t very stable or safe over the long term. It’s a form of instinct that you learn when you develop your skills with a system.
You wouldn’t put a laser tower on top of a tall stack of 2-stud bricks if you wanted the tower to withstand an alien attack. If you saw that you’d probably want to put the towers on several stacks of 8-stud bricks. Take that aliens!
Code smells are like that. When you look at code and can see things you know don’t work when the system gets larger or things that will lead to tight binding between separate systems. Those are code smells.
Just because you think a piece of code is smelly doesn’t mean that the code is bad. It does mean you should talk about the code nicely with someone else and find out it’s story if you can. Your code might be the work of many people over a long time and there’s probably a reason that it looks like that.
There are things in code which have a 'bad smell'. They may not always be bad by themselves, but they're a sign that there might be a larger problem. A warning sign.
Your finger hurts when you touch things. It is probably broken.
You can "smell" you code stink when it wasn't written properly.
The smell is just an indication. Some smells you recognize better than others.
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".
"Code smell" is a term to thrash-talk code without bringing up constructive criticism about its implications on security, performance or maintainability.