Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Why version strings?

by JavaFan (Canon)
on Mar 28, 2011 at 17:38 UTC ( #895978=note: print w/replies, xml ) Need Help??


in reply to Why version strings?

I've heard the argument that it allows you to switch off features introduced in the latest version but shouldn't it be done the other way round, ie. specify if you want limitations, not to enable what is available by default?
Neither is true.

First, use 5.XXX; has always had the meaning "your perl binary needs to be at least 5.XXX for the program to run". This could be because the program uses features not available before, or because a bug-fix essential for the correctness of the program happened in 5.XXX.

Now, since 5.10, use 5.010; also enables some of the new features of 5.10. Most of them you get regardless, whether you have an explicite use 5.010; or not. But a few features have the potential to clash with existing code; say is best known example. The alternative, a policy that's followed up to 5.10 is to not make say part of the language.

Since 5.12, use 5.012; could also introduce changes in behaviour. I'm not too fond of that - it means that if you take a program that has use 5.012;, and remove it or change it to say, use 5.010;, you don't get compilation errors (what you typically would get if do say "foo" and remove the use 5.010; statement), or even runtime errors. Your program just misbehaves - and it'll be hard to debug.

And don't say "don't do that". People have slapped on a use 5.XXX for too high versions. I've made 5.8 modules work on 5.6 by just removing the use 5.008;, and even further back by removing use 5.006; to get them working on 5.005. It was always safe to try - you'd get a compilation error if the use 5.006; or use 5.008; was indeed needed.

Perl never has used use 5.XXX; to impose limitations. The main purpose of use 5.XXX; is to signal "this code will not compile/run correctly on versions before 5.XXX". And you'd still get most of the functionality of 5.12 by just running 5.12, regardless whether you're using use 5.012; or not. (The only things you'll miss out on: say, given/when (but you do get smart match), state, Unicode strings and strict enabled). AFAIK, 5.14 will not introduce new features that aren't enabled by default.

Replies are listed 'Best First'.
Re^2: Why version strings?
by ikegami (Pope) on Mar 28, 2011 at 23:17 UTC

    Since 5.12, use 5.012; could also introduce changes in behaviour. I'm not too fond of that

    Since 5.10, actually. If there was no change in behaviour, there wouldn't be need for the features pragma at all.

    $ perl -e'sub say { print "foo\n"; } say for "bar";' foo $ perl -E'sub say { print "foo\n"; } say for "bar";' bar

    It was always safe to try

    It's no more or less safe to try now as then. By switching use 5.008; for use 5.006;, you could get bugs that changed behaviour and compile-time errors just like you do now.

    Update: Deleted a comment based on something I misread.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2021-05-11 14:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (117 votes). Check out past polls.

    Notices?