Pregunta

I'm hoping someone who's given this some thought can help me understand. Most style-checking tools seem to distinguish between warnings and errors.

To me, the point of a lint error is that a style issue ought to be fixed.

In the cases where the tool isn't smart enough to see that an exception can be made, many tools have a syntax for ignoring/acknowledging the errors. This makes sense too.

What cases are left where a warning might be of any use?

¿Fue útil?

Solución

Lint is not just about style-checking.

Many Lint tools do static code analysis. As such, they can detect errors in your code that would otherwise go undetected. That means you can screen your program for bugs before you run it.

The first Lint program was for the C language; it detected things like divide by zero, variables being used before they are set, and calculations likely to overflow. As the language standard improved and compilers got better at detecting and reporting errors, the Lint program gradually became less important. Today there's a Lint program for Javascript that Douglas Crockford wrote, which is still important because Javascript is still a young language.

Anyway, the point is that most of the coding style issues are more than likely warnings and not errors, because they are not going to cause your program to break. Things that will cause your program to break are classified as errors, not warnings.

Otros consejos

Lint errors mean something is broken, or will break at runtime. Guaranteed null pointer errors, divide by zero errors, etc. Stuff like this that is legal syntactically, but is nonsensical:

int x = 5 / 0;
int y = *((int *) 0);

Warnings should mean "this is risky, but not guaranteed to cause a runtime error or exception." Example:

bool x = true;
while (x = true) { // Oops! Should be "==" or just omit the test
  ...
}

Implicit conversions in C++ also come to mind, as does mixing signed and unsigned variables in a single expression. They can cause some very hard to track down bugs, but Lint or a good compiler can point them out as warnings. Not errors, because the programmer might actually mean it and it is not an error that will crash your program.

Licenciado bajo: CC-BY-SA con atribución
scroll top