3 ms·
You'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
by jlarocco 15y ago
You'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.