Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

tl;dr? See title.

It seems like we monks spend a significant amount of time admonishing Seekers of Perl Wisdom to use strict;, use warnings;, and the like. But when posting example code in response to someone's question, what do you include? I've recently begun to question my own habit of almost always including strict (or more recently, use VERSION), warnings, and even the oft-unnecessary shebang. I don't for one-liners or when interleaving multiple fragments among paragraph text.

If recent answers are any indication, equally experienced monks seem to favor both sides of the coin (including a few fans of Modern::Perl). I'm starting to think, however, that where these near-universal statements are concerned, less is more. Why?

First, there are already myriad places strongly urging strict and warnings, and people still submit questions with fundamental bugs which would have been caught had they heeded that advice. In those cases, I'm very likely to specifically mention strict/warnings and show the OP how those pragmas help solve their specific problem. However, in other cases, I doubt quietly including it at the top of my code that answers, say, how to refer the index of an array to another array of the same length is likely to cause an epiphany.

Second, two or three lines are sufficient to answer many questions. But those lines often get lost in the noise of the pragma parade, which significantly bloats the post. While conciseness isn't everything, see above paragraph, and ponder: do those extra lines help answer this poster's question? I believe most of the time, the answer is "no".

But then there is say. Without use 5.010; (or later), use feature 'say';, or perl -E, someone running my example code sees only a moderately unhelpful syntax error:

String found where operator expected at -e line 1, near "say "Just ano +ther Perl hacker,"" (Do you need to predeclare say?) syntax error at -e line 1, near "say "Just another Perl hacker,""

I use say() rather quite a lot, less so with some of the other new features. At what point do we assume (most) people get the picture and at least know how to turn the features on? A loaded question, I admit. Perhaps I'm jaded by the scores of "do my homework" posts, or perhaps posting answers without the necessary pragma is just begging additional confusion.

Finally, we're not a code writing service. I don't wish to make it overly difficult to run my examples, but my first responsibility is to improving the OP's understanding of Perl (and anyone else who's curious, I suppose). I'm not quite sure if that's an argument for or against.

All of this thinking has led me here: At the moment, I'm leaning toward dropping the boilerplate unless it seems directly relevant to the question, but updating my signature with a one-liner something like this:

Always assume use 5.012; use warnings; at the top of my examples. See feature, strict and warnings

What do the rest of you think? Perhaps I'm putting too much thought into this, but, then again, maybe putting this question to bed once and for all will silence that irritating voice in my head that starts muttering every time I wrap a two line example in four lines of boilerplate. :-)

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

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (8)
    As of 2018-03-20 15:25 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (254 votes). Check out past polls.