19 ms·
I 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,
by jlarocco 15y ago
I 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.
- btilly 15y agoFYI -c is just the Python equivalent of -e in Perl.
- deleted 15y ago[deleted]
- tomku 15y agoThe -c flag doesn't have anything to do with that behavior, it's just how you pass a one-liner as a command line argument. From the usage output: -c cmd : program passed in as string (terminates option list) Edit: fixed formatting.
- chromatic 15y agoYeah, I ran the wrong example code before I posted. Sorry for the noise.
- btilly 15y agoNo, YOU have missed the point. I'm not talking about syntax checking. I'm talking about getting a fast compile-time check for my most common mistakes. The default behavior that you demonstrated from Python is a run-time exception. Until you've gone through every code path, you have no idea whether you're going to trigger that exception. (Even 100% test suite coverage is not enough to guarantee that you won't blow up.) In even a moderate sized program, this can take a good while. By contrast Perl's behavior with strict is to blow up at compile time, before I begin running the program. This significantly shortens the edit/debug cycle for my most common mistakes. If you want the equivalent in Python, you have to use external tools like PyChecker. As for the defaults, there is nothing as hard to change as a misfeature. Everyone agrees that the default would be better if it was reversed, but there is no way to do so without losing backwards compatibility. And given how much critical infrastructure runs on Perl, backwards compatibility matters a lot.