Don't Use Warnings In Perl!

The Perl pragma “use warnings” is a major nuisance. But it is still part of the boilerplate code of many Perl module authors who are not aware to which extent they are harrassing their users and their users’ users by forcing them to become involuntary beta testers.

Wait a second! Isn’t it an established good practice in C to turn on all but the esoteric warnings? Why should it be bad practice in Perl?

There is a difference. C is a compiled language, C warnings are compiler warnings, they are compile-time warnings. Perl is an interpreted languages, and although it distinguishes between compile-time and run-time warnings, this distinction is completely artificial and incomprehensible for users. Compile-time and run-time warnings look the same to them. They look like run-time warnings. And they are a nuisance, an evidence of developer ignorance like unsolicited stack traces in Java or one of the languages following Java’s bad example.

The intended audience of automatically generated warnings is the author of the code. Users of the code, leave alone users of the users of the code should normally be left alone with such stuff. They can turn warnings on, when they feel the need for it.

But don’t they miss important information then? Especially other programmers using a library? No. I have written at least one million lines of Perl code and I have never ever found a problem in a third party module because of warnings turned on inside of it. And, honestly, most warnings produced by Perl are pretty useless (think of “Wide character in …” or similar nonsense).

But, hey, my fantastic module is free. The least that my users can do is to help out finding problems in the code. Well, then rather sell your software! Free software is about freedom not about free beer. If you want help from your users, ask first or pay for it.

But you must be ultimately wrong because “perldoc warnings” explicitly states that “use warnings” is favorable over the “-w” command-line switch because its scope is the enclosing block and it does not leak across file boundaries. So what? It is true but they forgot to mention that there is no easy way for users of the software to shut up these warnings.

Exactly for these reasons you as the module author in your development environment should run your own software with the “-w” command line switch or if you are developing a web application set the environment variable PERL5OPT to “-w” in you web server configuration. Package maintainers should probably do the same, end users only if they want to.

Warnings will be turned on globally then, and they are only visible for their intended audience, that is the author of the software, other professionals or interested users. It is their task then to set apart important warnings from sheer noise. The users will be thankful for not having their log files scattered with unsolicited debugging information for other people’s code.


blog comments powered by Disqus