http://www.perlmonks.org?node_id=756480

I am rather new to this site so I hope I don't bring up an issue that has been discussed before, but I propose the following:

Any posting asking for help on a particular piece of code that does not contain a "use strict" should get exactly one answer (put in a nice way of course):

First make your code compile under use strict, then - if you still have problems - post it again.

Or would that be too harsh?

  • Comment on Should code that does not use strict even be considered here?

Replies are listed 'Best First'.
Re: Should code that does not use strict even be considered here?
by JavaFan (Canon) on Apr 08, 2009 at 22:58 UTC
    Sillyness. I often downvote notes because all the poster has to say is "use strict" and/or "use warning" while adding strict and/or warnings would not have helped the OP to solve his or her problem.

    By all means, if code is posted which has a problem that reveals itself if strict or warnings had been used, point this out. But if a problem has nothing to do with strict and/or warning on, whining about it is just pointless clutter.

    If you don't want to help someone if (s)he doesn't use strict or warnings, fine. Just keep quiet and read the next post. But it is as silly as someone not giving directions for not wearing a seat belt.

    People should post code snippits. Long enough to identify the problem, but seldomly entire files. Unless it's relevant for the problem, don't post the code. Which, in most of the cases, means, don't post your 'use strict' or 'use warnings' lines. They won't matter.

      While I agree with most of your points, I do think many people fail by over-snippetizing code they post. In many, many cases I've seen, the part of code with an actual error is in the part that gets cut. I think a really good principle is to paste some stripped down version of the code (complete with enough variable definitions and data) that can actually be run by itself and produces the non-desired output. Often the mere act of composing such code answers the question, and if it doesn't, it greatly clarifies where the problem is.

      That said, I agree that if "use strict;" and/or "use warnings;" doesn't affect the code one way or the other, it might be worthwhile to mention it as a guideline, but the absence shouldn't stop anyone from helping with the real problem.

        That said, I agree that if "use strict;" and/or "use warnings;" doesn't affect the code one way or the other, it might be worthwhile to mention it as a guideline,
        Why? There millions of "good advices" one could give, but giving it to people without having any idea whether they already know that is irritating. If you ask the way to someone, and his response is "wear your seatbelts", are you happy for the good advice given? You probably already know it, it doesn't help you at all the solve your current problem, and the one who can give you directions moves on, thinking you already got help.

        Leave the uttering of irrelevant good advices to ones mother.

        And don't forget to wear a coat outside, or you'll catch a cold! (I expect many ++'s for this good advice).

Re: Should code that does not use strict even be considered here?
by Moriarty (Abbot) on Apr 08, 2009 at 22:34 UTC

    I see no reason why code that doesn't use strict should not be considered here. There is plenty of valid code that doesn't use strict. While using strict and warnings does catch most errors, neither are absolutely necessary for good code, but they are desirable, especially for beginners.

Re: Should code that does not use strict even be considered here?
by BrowserUk (Patriarch) on Apr 09, 2009 at 02:26 UTC
    I am rather new to this site ... I propose ... code that does not contain a "use strict" should get exactly one answer

    Why? Cos you say so?

    Cliche or truism? "You catch more flies with honey than with vinegar."

    This place has enough language lawyers, instant experts, and capricious, unwritten rules, without anyone mandating how everyone else should constrain their altruistic impulses, in order to comply with other people's (be they one or many) dogmas.

    FYI: I've used both strict and warnings in every Perl script I've written since I learned of their existance--which was just prior to the third Perl program I ever wrote.

    However, I've also seen some quite remarkable code written without one or both. And whilst they remain optional, I recognise that other people may arrive at a different conclusions to I regarding their value.

    Or, simply not yet encountered them--as with my first two Perl scripts.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Should code that does not use strict even be considered here?
by Your Mother (Archbishop) on Apr 08, 2009 at 22:35 UTC

    First make this SoPW post agreeable to everyone. When you can do that, post it again.

    Did that feel too harsh? :)

Re: Should code that does not use strict even be considered here?
by almut (Canon) on Apr 08, 2009 at 22:52 UTC

    Personally, I think that would be unnecessarily harsh (in particular to first-time posters), and kind of silly, too. It's up to everyone to decide for themselves whether or not to reply in those cases, or whether to point out that strictures would have helped.

Re: Should code that does not use strict even be considered here?
by shmem (Chancellor) on Apr 08, 2009 at 23:04 UTC

    This isn't a perl help desk. I don't follow any rules save those which I deem good to follow - and if others happen to follow the same rules, we make a lot.

    This is not a perl help desk! we are not required to process tickets, nor fake action in order to "have reacted" in order to suggest our customers to believe that being dealt with is being served.

    This site isn't about education. All here educate themselves in their own fashion for their lives to comprehend (or such). So no lifting finger at "dinn' use strict" either.

    "If you'd use strict ..." is really only for those cases where such usage would have given a hint and/or the solution to the question at hand, and prevented that post.

    I don't think what you propose would be "too harsh" to those to be given - but rather to those giving the advice. I can work out by myself where to post "use-strict-missing", thank you.

    use strict isn't a door-opener for help, and its lack no door-closer, either.

Re: Should code that does not use strict even be considered here?
by DrHyde (Prior) on Apr 09, 2009 at 10:12 UTC

    Consider a post like this:

    What does the colon mean in this line of code?

    $foo = $bar ? 42 : 69;

    To refuse to answer until the supplicant adds a pointless "use strict" would be silly.

    And then there's also the issue that not all the code posted here is in perl. There's C, and shell, and python, and ...

      And then there's also the issue that not all the code posted here is in perl. There's C, and shell, and python, and ...

      Do you actually think that OP wanted to have use strict; in non-perl code too?

        Well, he did say "Any posting asking for help on a particular piece of code that does not contain a 'use strict' should get exactly one answer" :-)

        But no, of course not. I don't believe he's that stupid. But it was still worth pointing out as an aside after my main point. Lots of people are under the mistaken belief that anything in <code> tags here is perl.

Re: Should code that does not use strict even be considered here?
by JavaFan (Canon) on Apr 09, 2009 at 06:52 UTC
    Just to be clear, slapping "use strict" and/or "use warnings" on a piece of code doesn't make code better. It may help the programmer in debugging his code, but in itself, it doesn't modify the quality of code.

    And, IMO, people who think its presence on code is a measure of its quality are still mere grasshoppers.

      It's not so much that its presence is a measure of quality, as that its absence is a warning that the code's author may have been inexperienced in the ways of Perl. As such it's a code smell -- one of those little things that make the reader start to feel uneasy about the quality of what they're looking at.

      Of course, I totally agree that it doesn't really make much sense to insist that they be included by law in all code posted here. I personally would only include them in a code snippet if I was posting something that was intended to be a complete module or script.

        as that its absence is a warning that the code's author may have been inexperienced in the ways of Perl.

        That may come to your mind at first glance. Read on. The code tells you about its author - use strict won't, and can't hide the stench, if any.

Re: Should code that does not use strict even be considered here?
by jdporter (Paladin) on Apr 09, 2009 at 20:16 UTC
    Any posting asking for help on a particular piece of code that does not contain a "use strict" should get exactly one answer (put in a nice way of course)

    There are already certain self-appointed strictness police who do exactly that. Personally, I find it tiresome. But I think people should be free both to post non-strict code, and to post admonitions to use strict. I'll stay out of the way. :-)

    Between the mind which plans and the hands which build, there must be a mediator... and this mediator must be the heart.
Re: Should code that does not use strict even be considered here?
by educated_foo (Vicar) on Apr 10, 2009 at 13:57 UTC
    ... and use diagnostics and Test::POD and Test::OfficialFlavorOfTheDay and... This attitude represents a superstitious silliness that is unfortunately common in the Perl community. The purpose of writing programs is not to chant the right rituals at the beginning.
      I have to agree. It's usually good advice but it's turning into cargo cult mentality, as the OP has unintentionally helped point out.

      Elda Taluta; Sarks Sark; Ark Arks

Re: Should code that does not use strict even be considered here?
by koolgirl (Hermit) on Apr 11, 2009 at 13:17 UTC

    I'm certainly no expert in the subject, however, it seems that I've noticed something quite different in Perl programmers than other programmers (that reference of course meaning someone who chooses to program in Perl consistently out of sheer love, worship, etc...., not just a typical general programmer who happens to know Perl), that difference being mainly a strong independent streak, and an un-willingness to follow the leader just because the rules say so. So, placing code-posting regulations on a Perl Monks site, seems to be a bit of a contradiction in logic; we're the renegades dam it, right? ;)

Re: Should code that does not use strict even be considered here?
by dragonchild (Archbishop) on Apr 12, 2009 at 16:23 UTC
    Go read CGI.pm, then reconsider your question.

    Yes, strictures and warnings are helpful tools, but nothing more.


    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: Should code that does not use strict even be considered here?
by Argel (Prior) on Apr 09, 2009 at 21:37 UTC
    The Monastery already has a mechanism in place to deal with this -- node reputation and experience points. If it bothers you then vote the node down and reply or /msg the OP letting that person know why downvoted the node. If enough Monks agree with you then the bad node reputation and lost experience points will likely encourage better behavior in the future.

    Of course, as you may have noticed, massive downvoting of these nodes is not happening. And thus the community has in effect already said that this issue is not as serious as you make it out to be.

    As an aside, you apparently have not really thought this out very well. What about code snippets? Code from other languages? Third party modules? Legacy code that cannot be changed? And so and so forth.

    Elda Taluta; Sarks Sark; Ark Arks

Re: Should code that does not use strict even be considered here?
by codeacrobat (Chaplain) on Apr 10, 2009 at 06:31 UTC
    Its not a shame to post short snippets without "use strict". But expect a downvote if the error is trivial to find by using strict (I am annoyed by these postings). General advice for the inexperienced. Don't risk making a fool of yourself use strict;

    print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});
      One of the things that annoys be about this "use strict" thing is that many people act as if "use strict" is the goal.

      It isn't. And only the programmer who just past the novice stage himself will think so.

      "use strict" can aid you to write good programs. But it isn't a goal in itself. And just patching your program so it satisfies "use strict" may improve your code a little bit, but it's a far cry from good programming.

      Say, for instance, someone posts a code fragment that uses, inside an if statement inside a sub something like:

      foreach $thingybob (@thingybobs) { ... }
      where $thingybob is only used inside the foreach. The typical grasshoppers Pavlov reaction will be "I've no idea how to solve your problem, but you should use strict". So, the OP slaps "use strict" on his program, notices the compile failure, remembers to declare all the variable, and puts "my $thingybob;" right below the "use strict" on top of his program. Hooray! Code now compiles under "use strict". Did his code actually increase in quality? No. In fact, I'd consider his code of less quality.

      Good advice (but still likely to not be relevant to his problem) would have been to tell him about narrow scopes. Writing

      foreach my $thingybob (@thingybobs) { ... }
      is what you want to see if you want better code. And that's the advice (if you insist on giving non-problem related advice) you should give.

      Don't focus on a possible tool. Focus on the goal.

Re: Should code that does not use strict even be considered here?
by morgon (Priest) on Apr 13, 2009 at 20:19 UTC
    Oh wow...

    I did not expect so much emotion...

    But the whole discussion about the philosophical merits of using or not using strict is pointless to me - if you think that not using strict is fine with you so be it - no problem on my side.

    I have just seen a lot of postings where people had code-problems that would have been obvious when run under strict, so I just got the feeling that when people with little Perl-experince used strict a little more a lot of trivial problems would get spotted immediately and they probably would not even need to ask the monks.

    But anyway please don't start another discussion - evidently everything is fine as it is.

Re: Should code that does not use strict even be considered here?
by mr_mischief (Monsignor) on Apr 09, 2009 at 19:20 UTC
    Yes.