Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

sartak (7900)

  (email not shown publicly)

Journal of sartak (7900)

Tuesday April 14, 2009
07:28 PM

Warnings are good, damnit!

[ #38810 ]

Warnings highlight possible bugs. The presence of a warning does not necessarily indicate a bug.

Only valid constructs will generate warnings! If a construct were invalid, then the system would have issued an error.

Warnings are not only for new learners. Warnings are also useful to experts, especially in the context of an evolving system. Delegating vigilance to the environment alleviates the burden of maintenance.

Changing code to cease its issuance of warnings usually requires disambiguation. This disambiguation is beneficial, because unambiguous code is clearer than ambiguous code. Encode your intent so that current collaborators and future maintainers will not have to guess at it.

If you truly require your code to run without warnings, then disable warnings entirely. The creation of warnings for potentially misleading or unexpected behavior should never require a battle. Existing code will not become incorrect, because warnings are not errors. However, you should still strive to correct the problems that issue warnings in new and maintained code.

edit: Some have missed the point of this post. I am not saying that having your code spew warnings is good in itself. I'm saying that having some warnings to alert you to suspicious code and to guide your fixes is what is good.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Existing code will not become incorrect

    Well... It depends on what you mean.

    Some warnings, for example with an unclean conversion of a string to a number, or use of uninitialized value, depends on your data, and when you're parsing data, the structure of that data may change over time, because after a year, people that entered the data may have changed some conventions. That way, you may suddenly start to get warnings where you never got them before. And more often than not, that is a reliable indication that things have gone wrong.