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


in reply to Re: Writing a better Modern::Perl
in thread Writing a better Modern::Perl

I still rather "use 5.010; use strict; use warnings;"

One less now

$ perl -e'use 5.012; print $x' Global symbol "$x" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.

Replies are listed 'Best First'.
Re^3: Writing a better Modern::Perl
by JavaFan (Canon) on Oct 08, 2010 at 16:17 UTC
    I will still write 'use strict;' even if I do a 'use 5.012'. It's a little effort, and I'm not going to assume everyone will know that at some point in time use 5.xxx implied use strict, and that they know at which point in time that was.

    Besides, writing "use 5.012;" without a "use strict;" runs the risk someone removes the "use 5.012;" (not unreasonable if there's nothing in the code that actually needs 5.012...), and then have it be without strict.

    I never liked the idea that "use 5.XXX" implies subtle changed behaviour other than "without the mentioned version, it's unlikely to compile". I prefer "use 5.XXX" to mean one of "if you try to compile this with 5.YYY, where YYY < XXX, you'll fail" or "this code will trigger a bug in 5.YYY, which was fixed in 5.XXX". The implicite turning on of strict isn't such a change. Now it mean "if you try to run this with 5.YYY, I'm going to keep quiet if you screw up". Not what I expect of a helpful language.

    I will only slap a "use 5.012;" label on my code if there's actually anything in my code that won't run on 5.010. So far, I've written next to no code that needs 5.012. I'm not going to artificially restrict my code to a certain version just so I don't have to type a few keystrokes (which I don't have to type in the first place - an editor macro does that for me).

      I will only slap a "use 5.012;" label on my code if there's actually anything in my code that won't run on 5.010.

      Me too.

      I will still write 'use strict;' even if I do a 'use 5.012'

      Me too. I've been requiring a Perl version in Makefile if necessary, and I use features to grab the features I use in the scripts and modules.

      or "this code will trigger a bug in 5.YYY, which was fixed in 5.XXX".

      There wouldn't be a need for a pragma in that scenario. features is used for backwards incompatible changes, not pure bug fixes.

      Now it mean "if you try to run this with 5.YYY, I'm going to keep quiet if you screw up". Not what I expect of a helpful language.

      I don't know what you mean. What errors does use 5.xxx; silence?

        or "this code will trigger a bug in 5.YYY, which was fixed in 5.XXX".
        There wouldn't be a need for a pragma in that scenario. features is used for backwards incompatible changes, not pure bug fixes.
        I may not have expressed myself well enough. What I mean is that sometimes I put a "use 5.006;" (to take an example) on the code, not because it uses a feature that isn't present in 5.005, but because it uses a construct that triggers a bug in 5.00504. (I remember a long debugging session related to regexes, where I was initially unable to reproduce to reported issue - it turned out the regex triggered a bug in one of the latest minor releases of the previous major release).
        Now it mean "if you try to run this with 5.YYY, I'm going to keep quiet if you screw up". Not what I expect of a helpful language.
        I don't know what you mean. What errors does use 5.xxx; silence?
        What I mean is the following:
        use 5.012; use warnings; ... code ...
        Note the absence of 'use strict;', because it's implied by the use 5.012. Someone comes along, who notices the code actually runs fine under 5.10 (its extensive test suite passes). Removal of the 'use 5.012' (or changing it to 'use 5.010') means that the code isn't protected by 'use strict'. Hence, any further modification of the code is subject to the same dangers any code without 'use strict' is.