Here's the deal: compiler warnings are functions. Functions require effort, and effort is a finite amount. (This can be measured in dollars or can be measured in the number of hours that someone wants to pass on to an open source project, but I assure you that this is of course.)
Therefore, we must highlight budgetary efforts. Every hour we carry out the design, implementation, testing and debugging of a function - this is an hour that we could spend on doing something else. Therefore, we are very careful to decide which features to add.
This is true for all functions. Alerts have special additional problems. The warning should be about code that has the following characteristics:
- Legal. Obviously, the code must be legal; if this is not legal, then this is not a warning, first of all, his mistake.
- Almost certainly wrong. A warning warning you of the correct, desirable code is a bad warning. (Also, if the code is correct, there must be a way to write the code so that the warning goes away.)
- Inobvious. Warnings should inform you of errors that are subtle and not obvious.
- Suitable for analysis. Some warnings are simply not possible; A warning that requires the compiler to solve a stop problem, for example, will not occur, since this is not possible.
- Other forms of testing are unlikely to be caught.
In your specific example, we see that some of these conditions are met. The code is legal and almost certainly incorrect. But is that obvious? Someone can easily look at the code and see that it is infinite recursion; warning doesn't help much. Is he fit for analysis? The trivial example you give, but the general problem of finding unlimited recursions is equivalent to solving the stop problem. Is it likely that he will be caught by other forms of testing? No. The moment you run this code in a test case, you will get an exception in which you will indicate exactly what is wrong.
Therefore, we should not make this warning. There are better ways we could spend this budget.
Eric Lippert Jan 06 '12 at 18:39 2012-01-06 18:39
source share