Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-03-29 14:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found