Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: When do you include the usual use pragmas in your example code?

by davido (Archbishop)
on Aug 03, 2013 at 16:45 UTC ( #1047723=note: print w/replies, xml ) Need Help??

in reply to When do you include the usual use pragmas in your example code?

I used to show use strict; and use warnings; at the top of almost all of my example code. Then I read and thought a lot about MJD's "Twelve Views, #8: Why I Hate strict". From that article, there's this:

People come into the Usenet comp.lang.perl.misc group with some question, which they demonstrate with a four-line example program, and other folks there jump on them: ``Why didn't you use strict?'' Well, because it's a four-line example program I concocted as an example in my Usenet article---duh!

After digesting that article I kind of shifted my thinking a bit. Now, often I'll post only the code necessary to demonstrate my point. Usually it's stand-alone and runnable. Occasionally just a snippet. I will use lexical variables almost always, but may not explicitly demonstrate "strict" and "warnings" if they're not part of the solution, or part of the point I'm trying to make.

If I do advocate for the use of strictures and warnings, I'll also try to point out which aspect of "strict" would have caught some problem in the user's code, or which warning might have been raised had warnings been enabled. I feel this is far more helpful than simply carping "You should use strict and warnings." Another quote from the article:

Any time you hear anyone saying ``you should be using strict,'' you can be fairly sure they're not thinking about what they're saying, because strict has these three completely unrelated effects. A more thoughtful remark is ``you should be using strict 'vars''' (or whatever). As an exercise in preventing strict zombie-ism, ask yourself ``Which of the three strict effects do I find most useful? Which do I find least useful?''


Replies are listed 'Best First'.
Re^2: When do you include the usual use pragmas in your example code?
by educated_foo (Vicar) on Nov 07, 2013 at 01:53 UTC
    Too few people have read that MJD piece, much less understood it. Seeing it again now just makes me sad about what Perl and, much more, its community have become.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047723]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2017-03-29 01:53 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (343 votes). Check out past polls.