3 ms·
I remember when I felt as he does about strict. I also remember the day that I made a trivial error that strict would have instantly caught, and took out Bloom
by btilly 15y ago
I remember when I felt as he does about strict.
I also remember the day that I made a trivial error that strict would have instantly caught, and took out Bloomberg's ftp server as a result. That was also the day that I was converted.
It is important to know what strict does and doesn't do. It is not a panacea. But that said, it is a very good default to have on. But most days it catches problems for me, and they are usually real bugs. Keeping it quiet involves very little work. And my experience seems typical.
I believe him when he says that he has lots of working scripts that don't use it. However I also believe that a habit of using it would improve his productivity. And based on past experience, I'd be willing to bet that if he put strict on those scripts, he'd find and fix at least one real bug. (And probably a lot more.)
Given how useful strict is, why shouldn't it be a default "best practice" that gets recommended? This is not nagging. This is sharing useful information that makes people's life better. I've had people thank me for it.
- zby 15y agoYou write that it is not nagging - but you don't really know that guys experience. I can very well imagine some internet pundits nagging him about it. But yeah - I wrote that only as a devil's advocate :)
- __david__ 15y agoI have same experiences as you. I can remember arguing with my friend about how inflexible "use strict" made Perl feel--Like it was trying to force C idioms onto a dynamic language (having to define variables, for example). But yeah, after running into bug after bug in my programs I finally saw the light... The Perl community has pretty clearly collectively decided that "use strict" is the thing to do. I firmly believe the only reason it isn't the default behavior of Perl is because the core community holds backwards compatibility in such high regard.
- jlarocco 15y agoI think part of the point he's making is that it's easier to just use a language where the "safer" option is the default. Then I don't need to worry about it, and I don't have to listen to people repeat the same thing over and over. And to be honest, people constantly pointing out the same advice over and over gets old. An occasional, "Hey, did you know..." with some new advice is cool, but people have been beating a dead horse with "use strict" and "use warnings". If somebody isn't using strict, it's not because they don't know about it.
- btilly 15y agoI find this statement ironic when the language he moved to is Python, and Python does not offer the direct equivalent of strict. (Though there are external verification tools that do. But it is not built into the language.) In Perl if I have a typo in my variable names or function calls, it gets flagged by strict vars or subs respectively. As for people not using strict, someone who is not using strict at this point in Perl either has very good reason (eg Damian Conway) or is sabotaging themselves.
- jlarocco 15y agoYou're still missing the point. It's not about having a syntax checker. It's about removing the onus from the user and putting it on the compiler/interpreter writer. Compare what happens when running: perl -e "print \"\$bob = $bob\";" perl -e "use strict;print \"\$bob = $bob\";" python -c "print('bob = ', bob)" Python throws an exception and warns about the undeclared variable automatically. It has the same behavior as "use strict", and I didn't have to do anything to get it. Perl makes the special case that's bad 99.999% of the time (you've basically said as much yourself) the default. At the very least, reverse the situation, make "use strict" implied, and add a "use unsafe" or something.
- chromatic 15y agoI didn't have to do anything to get it. You had to use -c; how often do you see Python programmers do so? With that said, strict mode should be the default for Perl 5 programs. Having to know the magic incantation to ask the compiler to help you is a barrier to novices.
- bigiain 15y agoAs a long time Perl guy (I had a few websites break when my ISP upgraded from Perl4 and all my email addresses broke with unescaped @ symbols), I think of strict and warnings as being like speed limits. It's a _really_ good idea for inexperienced drivers/perl-programmers to stick to them. Once you've got a bit of experience behind you, you can choose when to ignore that good advice - and just like teenaged boys in cars, mostly people make that choice before they're actually experienced enough to have made a good call, and the near-misses/speeding-tickets/accidents as a result of those poor calls is what ends up becoming the foundations of real experience later on. I'm firmly of the opinion that telling everybody (especially inexperienced Perl programmers) "you've got to use strict and warnings" is the right approach - with the unstated acknowledgement that if you know what you're doing and are prepared to accept the risks, you'll occasionally choose to ignore that advice.