My code samples of the past couple of days have led to a few requests for warnings, which reminds me of a story. So gather round old Grandpa Gunnerson. Like many such stories, this is something I’ve said before – probably on this very blog – but I can’t find anything through search, so you’ll have to bear with me if you’ve heard it before, and when I’m done, we’ll all go out for ice cream.
Back in the previous century, I worked on the VC++ compiler team as a test lead. Given the amount of rope you have in the C++ language, we spent some time one release talking about adding some new warnings to the language for questionable behavior, and ended up adding a few. Because of the nature of the language and the warnings, they were 50/50 things – about half the time the warning was useful, and the other half it wasn’t. Because lots of users compile with “warn as error” turned on, we had to put them at a high warning level (level 3 or 4).
Which meant that 98% of our users never benefitted from the warning. In other words, we were just wasting our time.
We stopped adding level 3 or 4 warnings at that point.
Thankfully, C# has much less of a problem in this arena, but there are still some tricky areas, and we considered warnings for them. But we ended up implementing very few, since there is nothing more annoying then getting warnings that you have no way of shutting off, or (in V2), where you have to modify your code just to shut the compiler up.
If it’s dangerous, you should consider whether it should be removed from the language or made more explicit. If it’s not dangerous but more in the advisory vein, it belongs in a tool like FXCop.
Now somebody find me my teeth, and we’ll be going…