I’m sitting on the balcony right now, after some serious sleeping (14 h) with a cup of coffee in my hand and questions on my mind. Last night I stayed up late on Twitter, and we had a bit of a talk/debate about the last question, ‘What is a tuple and what can I use it for’? And so we got into the code smell talk and I realized that I haven’t really thought too much about what we mean by that term and decided it would be a perfect question for today. And I will spend a whole week dedicated to this term, and go through 6 more questions that are related- but, let’s answer this one first.
Code smell is a part code (large or small) that might indicate that something is wrong, that there is a deeper underlying problem. By this I mean that the code itself isn’t necessarily breaking anything, but that it shares common traits with code written that way as a quick fix or result of an underlying problem.
When I was working on a project with some serious issues I used to call it duct-tapping. You’ve smashed your car up, but instead of fixing it you’ll just get the duct-tape out and fix the other bits and pieces. Of course this will only work so long, you’ll need more and more tape as more cracks appear- until the whole thing breaks down on you. You would have been better of fixing the underlying problem, be that you’re driving skills, the car or something else.
And why ‘smell’? The ‘smell’ part is indicating that you can smell something, and you should follow that smell to locate the source of the smell – and fix that. It’s like covering up the smell of sweat with a perfume,- you should probably take a shower instead. For me it feels more like watching something that I think is ugly, and it is the same with design (design is interesting, but it is complicated and I prefer to ask the pro’s about advice as it is more than just making something pretty). Only this week I’ve called my dear friend Kim Brockie for UI design advice and said (while sharing the screen) – what’s wrong here? I don’t like it but I don’t know why. And it’s the same with code, I’ll just get a gut feeling that something is wrong, and I’ll usually grab one of my coworkers and ask – what is wrong with this picture and what can I do? Having a second nose, or more, around can be really helpfull to analyze smells 😀