One of the oft-cited reasons for wanting a Perl 7 to change language
defaults (like enabling strict and warnings by default) has been the
consideration of newbie users, new people we hope to bring to the Perl
community. The idea has been asserted that new defaults would be
beneficial to them.
If we could somehow magically stop the entire world, update every
single perl installation with a Perl 7 and ensure that nobody anywhere
was running an older version and start the world again, then it might
seem that "new defaults" would be nice. It'd make simpler code.
But we can't do that. Even with the most perfect and timely execution
on a "Perl 7" release the world will continue in a mixed 5-or-7 state
for a long time. I'm not just considering installed interpreters, but
also books, tutorials, online articles, ... All those things that affect
newbies a lot more than the more entrenched experienced programmers.
There will remain for a long time many sources of learning for these
new programmers that talk about "the old ways" - i.e. Perl 5 defaults.
We may be doing those new users a disservice if we go out and create a
world in which suddenly there are "two different kinds of perl" and it
is impossible for them to look at an online tutorial and know if it's
good or not. The version of perl they're running has to match the
version the tutorial was written for, and it may not be obvious -
doubly so to the newbies it is aimed at.
Lets take for example, this tutorial snippet I just made up:
#!/usr/bin/perl
open my $fh, "<", "data.txt" or die "Cannot open - $!";
It's a reasonable example in most ways (lexical filehandle, 3arg open,
checks for failure) - but youknow, it didn't start with `use strict;
use warnings;` - that's bad right?
Well... kinda? But in the new world of new defaults for 7, that's OK.
Those are on by default. So maybe this example is fine. But how does
someone know that just by looking at the example that we're aiming at
7. The example doesn't say 7 anywhere on it.
What happens if this newbie user runs it on their existing perl 5?
They're a newbie - they don't necessarily know to check the distinction
between 5 and 7 - why would they? They just run it - and of course, it
works fine. So they'll carry on writing... maybe they'll succeed in
their task, or maybe they'll do something wrong that, had they had
strict+warnings enabled, perl would have told them about. But because
they're running on 5, not 7, those defaults didn't apply.
We've now just annoyed and confused this new user. At this point it's a
bit late to explain "Oh yes so perl didn't used to do that but we just
assumed in the tutorial you'd be running a new perl so we didn't bother
to tell you".
Perhaps then, my original tutorial example was wrong, and sent newbie
users off in the wrong direction. A far better tutorial would therefore
be:
#!/usr/bin/perl
use v7;
open my $fh, "<", "data.txt" or die "Cannot open - $!";
And hey presto - all the newbie users are now in a far better position.
Anyone running on perl 7 already doesn't notice any difference
whatsoever - all is fine. But anyone still running on an older perl 5
gets a far better result, in that the example complains
Perl v7.0.0 required--this is only v5.30.3, stopped at ...
So it would seem that in order to be nice and friendly to these new
users (who surely aren't going to bother to check `perl --version`
before they run tutorials) we all ought to be strongly encouraging the
use of a `use v7` line in all the code and examples anyway.
I'm not thinking here about seasoned professionals maintaining old
crufty installations, or mid-way maintainers of new and exciting but
well-written code. I'm purely looking at new users trying to take their
first steps into the world of Perl by reading some online examples and
tutorials.
Do folks agree here? In summary, that:
To best help newbie users coming to Perl via tutorials and examples,
it is important that we always show `use v7` at the top of all the
code to ensure that they get the right behaviour if their perl version
is too old.
--
Paul "LeoNerd" Evans
leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
defaults (like enabling strict and warnings by default) has been the
consideration of newbie users, new people we hope to bring to the Perl
community. The idea has been asserted that new defaults would be
beneficial to them.
If we could somehow magically stop the entire world, update every
single perl installation with a Perl 7 and ensure that nobody anywhere
was running an older version and start the world again, then it might
seem that "new defaults" would be nice. It'd make simpler code.
But we can't do that. Even with the most perfect and timely execution
on a "Perl 7" release the world will continue in a mixed 5-or-7 state
for a long time. I'm not just considering installed interpreters, but
also books, tutorials, online articles, ... All those things that affect
newbies a lot more than the more entrenched experienced programmers.
There will remain for a long time many sources of learning for these
new programmers that talk about "the old ways" - i.e. Perl 5 defaults.
We may be doing those new users a disservice if we go out and create a
world in which suddenly there are "two different kinds of perl" and it
is impossible for them to look at an online tutorial and know if it's
good or not. The version of perl they're running has to match the
version the tutorial was written for, and it may not be obvious -
doubly so to the newbies it is aimed at.
Lets take for example, this tutorial snippet I just made up:
#!/usr/bin/perl
open my $fh, "<", "data.txt" or die "Cannot open - $!";
It's a reasonable example in most ways (lexical filehandle, 3arg open,
checks for failure) - but youknow, it didn't start with `use strict;
use warnings;` - that's bad right?
Well... kinda? But in the new world of new defaults for 7, that's OK.
Those are on by default. So maybe this example is fine. But how does
someone know that just by looking at the example that we're aiming at
7. The example doesn't say 7 anywhere on it.
What happens if this newbie user runs it on their existing perl 5?
They're a newbie - they don't necessarily know to check the distinction
between 5 and 7 - why would they? They just run it - and of course, it
works fine. So they'll carry on writing... maybe they'll succeed in
their task, or maybe they'll do something wrong that, had they had
strict+warnings enabled, perl would have told them about. But because
they're running on 5, not 7, those defaults didn't apply.
We've now just annoyed and confused this new user. At this point it's a
bit late to explain "Oh yes so perl didn't used to do that but we just
assumed in the tutorial you'd be running a new perl so we didn't bother
to tell you".
Perhaps then, my original tutorial example was wrong, and sent newbie
users off in the wrong direction. A far better tutorial would therefore
be:
#!/usr/bin/perl
use v7;
open my $fh, "<", "data.txt" or die "Cannot open - $!";
And hey presto - all the newbie users are now in a far better position.
Anyone running on perl 7 already doesn't notice any difference
whatsoever - all is fine. But anyone still running on an older perl 5
gets a far better result, in that the example complains
Perl v7.0.0 required--this is only v5.30.3, stopped at ...
So it would seem that in order to be nice and friendly to these new
users (who surely aren't going to bother to check `perl --version`
before they run tutorials) we all ought to be strongly encouraging the
use of a `use v7` line in all the code and examples anyway.
I'm not thinking here about seasoned professionals maintaining old
crufty installations, or mid-way maintainers of new and exciting but
well-written code. I'm purely looking at new users trying to take their
first steps into the world of Perl by reading some online examples and
tutorials.
Do folks agree here? In summary, that:
To best help newbie users coming to Perl via tutorials and examples,
it is important that we always show `use v7` at the top of all the
code to ensure that they get the right behaviour if their perl version
is too old.
--
Paul "LeoNerd" Evans
leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/