warnings is better than -w

s/better than/different from/.

warnings.pm was created (based on the justifications I've seen repeatedly expressed) to address a specific problem that was sometimes annoying with -w. It also (at least now) includes several less-often-used features that are rather tangential to a comparison against -w.

But (not too surprisingly, at least to me) it also introduced new annoyances, some of which are improved by using good, old -w.

I have a version of a module that does 'use warnings;' and the biggest problem with that version is that it produces a warning for no good reason and there is no good way to prevent that. This is almost identical to the annoyance that appears to have motivated the creation of warnings.pm and is often used as justification for calls to replace '-w' with 'use warnings;' (just in reverse).

I use -w a lot more often than I write use warnings;.

In unit tests for a module, I use -w because I want to see warnings not just in the unit test code and not just in the module being tested, but also warnings caused in other modules by values (usually undef) leaked from my module.

Similarly, in scripts where I'll see the warnings, I use -w for similar reasons.

In my modules, I usually do neither because I think it should be up to the user of the module as to whether or not they want to see warnings from my module, especially since such would likely be caused by values leaked in from outside of my module (or by cases that I didn't run into when testing -- note that CPAN testers don't send you reports about warnings produced by your module test suite on some version of Perl that you haven't used recently).

Also, I've observed that, in general, warnings are usually pretty useless when delivered to somebody other than the author (or a maintainer) of the code most responsible for the warning. So putting 'use warnings;' in my module to force the display of warnings to people who merely make use of my module seems of little value (and, if having any consequence, is most likely to lead to annoyance).

It is the rare case that I want to enable warnings only for a lexical scope and also have a good reason to avoid warnings from other lexical scopes (and so choose to not see warnings due to data leaking out of that scope).

'no warnings ...;' is a feature I find quite useful. I may even write that more often than I write 'use warnings;', though still relatively rarely.

- tye        


In reply to Re^2: This code snippet causes Perl to SEGV (-w++) by tye
in thread This code snippet causes Perl to SEGV by worenklein

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.