Frama-C news and ideas

To content | To menu | To search | Frama-C Home

Code smells smell

This blog post is on the subject of “code smells” and what is wrong with them. I initially wanted to go with the title “Code smells are crap”. That made it clearer that the title was grammatically a sentence, with “code smells” a nominal group followed by a verb. But there seems to be something in this blog's content management system that censors four-letter words in the title of articles, like some sort of administrator or something[1] friendly moderator[2].


At the time of this writing, Wikipedia defines a code smell as “any symptom in the source code of a program that possibly indicates a deeper problem”. I do not challenge this definition. Indeed, to the best of my knowledge this is exactly the meaning many researchers (and engineers) working in software engineering intend when they talk of “code smells”. I think, however, that there is something fundamentally wrong, not with the definition, but with scientific use of any notion accurately described by this definition. The issue I see, in so many words, is that it is not falsifiable.

Say that you build a tool that detects “code smells”. You might even call your tool a “static analyzer”, and there might be so many of you and of your tools that “static analysis” is understood by the majority as the craft of building code smell detectors. The tool flags as smelly a diligent implementation of a subtle but efficient computation taken from The Art of Computer Programming. This deserves the name “false positive”, right? Surely your tool does not pretend to judge Knuth's carefully crafted, state-of-the-art algorithms? Ah, but no, it is not a false positive, because the notion is built right in the definition that a code smell only “possibly indicates a deeper problem”. Whatever the tool found is a code smell by virtue of having been flagged by the tool. It was not a problem, but it was a code smell because it could have indicated a problem.


As scientists, what the four-letter word are we supposed to do with such a notion?

Notes

[1] This post was crying so loud for moderation that it would have been a shame not to grant it

[2] a special kind of facetious colleague

Comments

1. On Wednesday, July 25 2012, 17:01 by Jason Baker

Coding isn't a precise science. Stop trying to turn it into one.

The idea of a "code smell" wasn't meant for scientists. It was meant for engineers who sometimes need to make practical decisions on very little data. If I see a method that has say feature envy, I know that I might want to look and see if I should shuffle some methods around. It's simply not possible (and maybe not even preferable) to make such a decision based solely on firm science.

Now... that said, the question of whether or not static analysis tools should detect such code smells is an entirely different question. I think your answer is a valid one, albeit one that I'm a bit ambivalent about.

2. On Wednesday, July 25 2012, 20:01 by pascal

@Jason

The definitive title of my post was “Code smells smell”, so I can claim that I did not say “code smell” was a bad notion per se, only that it could be dangerous and should be watched (see what I did there?).

The notion may be useful to the engineer, which I do not challenge. Some people are making scientific claims about code smells, using scientific vocabulary. Heck, these people even call themselves “computer science researchers”, which counts twice, once for “science” and once for “researchers”. This blog post is more about these people and their claims than it is about the notion of a code smell or about engineers. And I will continue to warn about what looks suspiciously like cargo cult science until these people start calling themselves “computer craftsmanship scholars“.