perl 5.12, strict by default

tsee on 2007-12-27T17:10:24

So I did it. I proposed to the perl5-porters that we should enable "use strict" by default for some future code. This may be a little less preposterous than it sounds at first, so please wait with hitting the "reply" button until you read the whole of this.

My proposal basically goes as follows:

  • Add a feature called "strict" to feature.pm.
  • Include that feature into the set of default features which are loaded by "use feature ':5.11'" or even just "use 5.11.0;".
  • Add a special case for the -E switch to perl so strictures aren't enabled by default for one-liners.

I'll include my original rationale here:

Personally, I've always wanted perl to have strictures on by default for my code. I would think that 95% of all code bases which were written in this century and which are of non-negligible size import "strict". I don't use strictures for one-liners, of course, but for anything else it's a must. It seems to me like others have similar views on this. Try posting some code without "use strict" to some newsgroup or forum and ask for help. Make sure not to give out your email address, though.

"use 5.10.0;" already auto-imports feature.pm and loads the 5.10 specific features.

How about having "use 5.11.0;" (or 5.12.0) automatically import strict along with the 5.10+5.11 feature set? Naturally, the -E switch for one-liners should *not* do that.

This would *not* break backwards compatibility. This would not affect one-liners. This would optimize for the common case: If you write enough code to make importing optional features worthwhile, odds are very high you'd be importing "strict" anyway. The 5% who need to disable strictures again can still add a "no strict;" statement.

strictures-correct code has been best-practice for a long time now. Let's make it the default for *new* code.

Just think of strictures as a feature. It just makes sense.

To my surprise, the proposal has been received with very positive feedback. So I wrote the patch.

With some luck, we'll get strictures by default in 5.12! Flame away!

Cheers,
Steffen


bad idea

slanning on 2007-12-27T17:24:00

It's anti-Perl. Leave aside the logical arguments, like the inability of sysadmins everywhere to update their systems because of their crappy code. When default strictures happen, we'll know that Perl is, finally, in fact dead. It would really limit obfuscation and poetry, after all. Next thing you'll be wanting us to indent blocks by a fixed amount of whitespace. It's fascist!

Re:bad idea

Aristotle on 2007-12-27T18:04:58

Really. All those sysadmins’ existing crappy scripts will magically grow a use 5.012; line at the top of the script. Amazing.

Re:bad idea

tsee on 2007-12-27T18:09:41

Please re-read the proposal. It happens only if you explicitly ask for 5.12.0 features.

Cheers,
Steffen

Re:bad idea

slanning on 2007-12-27T19:27:13

Ah.... hmmm, calling it "by default" could be a bit misleading, then. Anyway, I was exaggerating my reply. :)

Re:bad idea

sigzero on 2007-12-27T18:46:01

I think it is anti-Perl as well.

Re:bad idea

jhi on 2007-12-28T15:40:47

You are anti-Larry.

http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2007-12/msg00842.html

Not sure what the opposite of a flame is...

Adrian on 2007-12-27T18:07:23

... but that's what you'd be getting from me.

I'd enable warnings too :-)

The opposite of a flame is a bucket of cold water

Ron Savage on 2007-12-27T22:44:26

I vote for use strict /and/ use warnings both being enabled.

+1 from me

Alias on 2007-12-27T23:48:27

Having warnings enabled by default can sometimes be problematic, for example Apache error logs do have cases where warning spam blows them up (so I don't generally enable warnings in production unless we're seeing problems).

But having "use 5.012" implicitly mean "use strict;" can only be positive as far as I can see.

It upgrades one good practice (using strict) to an even better practice (always declaring minimum Perl version compatibility).