I just got the mail about opening up this discussion, so thought I’d give it a try…
Basically, there are hundreds of Code Smell rules. Some of them are pretty straightforward and all our devs agree these are good rules to follow.
But there are others, particularly those I like to call “too many notes” rules. In the 80’s movie Amadeus, there’s a scene where someone tells Mozart his music has “too many notes,” and the doofus emperor (*) agrees. Mozart objects that his music has the exact number of notes required, no more and no less.
So there are rules (many of them parameterized) like don’t have too many lines in a method, or too much complexity (computed by a mechanistic formula), or nest too deeply or whatever. There are other rules that are not really limit-based, but are general prohibitions, like ternaries. Some of these led to big discussions when I talked about enabling them.
From my experience, when a rigid rule is made, many people (who are pressed for time, like we all are) will find a quick-and-dirty fix to pass whatever automated system was flagging them. My favorite “horror story”: as a lowly intern I was assigned some code auditing tasks. (Not sure if that meant they thought highly of me, or poorly of code audits. ) I saw one example where there was a rigid 100-line limit to functions. When a function expanded past this limit, the dev just split it into two functions, and passed all the intermediate data that was live at the end of the first function into the second function via a bunch of global variables!!!
To use the “smell” metaphor, that was a bit like having a skunk spray the room to mask a tobacco smell!
Anyway, we decided that some of these rules are more like “hints.” So we made our own tag, starting with cstm (see Reserved or open tag names?) to mark certain rules. We have a formal review process, and the policy is that if a smell rule has this tag, you’re allowed to violate the rule, but only if the reviewer agrees that the alternatives are even smellier. And we add notes to the rule description to give more clarification.
How do other people feel about these rules? Do you have similar policies, or do you just turn off those borderline cases?
(*) Historians say the real emperor wasn’t the doofus portrayed in the movie. In fact, most of the portrayals in the movie were way off, starting with Salieri.