Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: This code snippet causes Perl to SEGV (-w++)

by tye (Sage)
on Aug 22, 2012 at 01:23 UTC ( [id://988920]=note: print w/replies, xml ) Need Help??


in reply to Re: This code snippet causes Perl to SEGV
in thread This code snippet causes Perl to SEGV

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        

Replies are listed 'Best First'.
Re^3: This code snippet causes Perl to SEGV (-w++)
by Anonymous Monk on Aug 22, 2012 at 02:47 UTC
    No, better, precisely for the reason you listed --- using -w turns on warnings for code you did not write

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://988920]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-03-28 14:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found