4 ms·
I much prefer Python's argument-passing to Perl's barely-there conventions. Python gives me positional arguments, named arguments, named positional arguments,
by neild 16y ago
I much prefer Python's argument-passing to Perl's barely-there conventions. Python gives me positional arguments, named arguments, named positional arguments, required arguments, and default values. Perl gives me @_. I can, of course, build almost everything that Python gives me using @_, but I'd rather not have to do it all.
For example, I can write:
def frobnicate(a, b, snozz=True):
pass
frobnicate(1, 2)
frobnicate(a=1, b=2)
frobnicate(1, 2, False)
frobnicate(1, 2, snozz=False)
frobnicate(1) # Error, need to pass at least two args.
frobnicate(1, 2, snooze=False) # Error, no such argument.
I'm certain there's a "Modern" Perl module that will help with doing this sort of thing, but it's nice to have it there in the language. Back when I wrote a lot of Perl, I'd always end up with something like this:
sub frobnicate {
my($a, $b, %args) = @_;
$args{snozz} //= 1;
}
frobnicate(1, 2);
frobnicate(1, 2, snozz => 0);
Of course, this doesn't include any of the basic error checking I get for free in Python.
I like having OO support in the language syntax. Yes, Perl has Moose now, but the blending of packages and classes is still there. In Python, I can declare a new class with just a couple lines of code; even a minimal Moose class declaration takes substantially more. For example:
class XPathError(Exception):
"""Base exception class for all XPath exceptions."""
Two lines of code to get a useful class.
That, of course, ties into one of Perl's big weaknesses, which is exception handling. I know that there are modules which try to patch over Perl's very weak exception handling model, but again, Python is just so much better. What's the Perl equivalent of this?
try:
x = int(s)
except ValueError:
x = 42
Perl's core still uses strings for exceptions, which is just horribly fragile and painful to deal with. Python has solid, pervasive exception handling with exceptions defined as objects in a sane and simple hierarchy.
I like the fact that people understand Python. I was a pretty good Perl coder, back in the day, and I like to think I had a quite deep understanding of the language. The problem was that I kept dealing with code written by people who didn't. To some degree, this is a problem in any language, but Perl contains so many traps and pitfalls for the unwary.
Consider context. I understand the difference between scalar context and list context. I understand why the following two lines of code are equivalent:
foo(1, 2, 3, 4, 5, 6);
foo(1, (2, 3, (4), ((((5))))), 6);
I understand when the above lines aren't equivalent.
But entirely too many people don't understand this. And, in my opinion, they shouldn't have to. I've never once missed list flattening in Python.
Perl is big and complicated and powerful. Some of that complexity is wonderful, but I find that I don't really miss any of it. Python isn't as big, and it isn't as complicated, but it's just as powerful for me.
I haven't missed CPAN. It's a wonderful collection of code, but Python's PyPi (formerly the cheeseshop) is also wonderful. We could quibble about what packages are available for each language or the technical details of CPAN vs. PyPi, but let's just say that I'm happy with both.
I could go on.
Let's just say, however, that I've found there's nothing in Perl that I can't do faster, easier, or more maintainably in Python. Oh, there's the occasional area where I take a couple lines more code to do something in Python. There's also the occasional area where I take a couple lines less. But, overall, things just feel cleaner to me in Python.
I used to love Perl unreservedly, but I've been over it for some time now. When I go back, the idiosyncrasies that I once found charming just annoy me. I've moved on.
You still like Perl, and that's fine. I hope I've given you some sense, however, of why some of us prefer other languages.
- berntb 16y ago>>You still like Perl, and that's fine. I hope I've given you some sense, however, of why some of us prefer other languages. Frankly, we have all seen the arguments -- when Perl is mentioned on e.g. HN there are always lots of Python lovers which love to tell us them... It is BTW nice to have OO built in -- and it is nice to have a better OO system in Perl's Moose. And so one. And so on. And so on. :-( IMHO, the main problem with Perl is the complexity/learning time; the good part is that it is fun. I promised myself a few years ago that if I should work more with computers, it would be things that made me happy. You were at least polite and informed, but after all those language war lovers, if I change it will be to Ruby. :-) But sure, come back when it is neat in Python to copy/paste code with variant indentations [Edit: -- and write decent one liners, I never use the REPL]... :-) Edit: And sure, chromatic wrote that -- as answer to yet another Python trolling... Edit 2: We have seen the arguments. Before Moose, the Perl OO was derided as a killing problem -- now Moose which is arguably better OO than Python -- is dismissed. And so on.
- neild 16y agoI was responding to a comment in which chromatic specifically asked for reasons to prefer Python over Perl. As such, "we have all seen the arguments" is needlessly dismissive at best.
- berntb 16y ago[Edit: This was days later, the one I comment on might never see it. It is just for my personal peace of mind to answer seriously, despite that the subject is a bit more flaming material than editors.] In hindsight, it doesn't feel good just to answer by a couple of edits on my GF comment. First, as I wrote, the way how the arguments change over time is irritating -- now you dismissed not only CPAN but also that the OO afaik is superior to Python. Perl is messy and complex from its natural language inspiration. The main problem with that is the learning time. (Given that you work with non-newbies that can document and follow coding standards.) The advantage with being messy is that growth happens in more areas. Moose is arguably a better OO then Python at this time. There are now standard ways of extending the language. Etc. (You could call it "better evolvability".) Personally, I like the insanity -- that Perl breaks most every design rule for programming languages that ever existed, but still works. Well, that and the smart and laid back people of the community. That is what keeps me using Perl; it puts a smile on my face and keep me happy. When the day ends, motivation is everything. I can't get out of bed in the mornings just for money... But... I am not religious. A job offer with a nice Lisp variant would tempt me. I should get a book about Haskell and read. Or maybe Perl 6. To change between Ruby, Perl and Python do seem totally meaningless, they mostly fill the same niche. Which is why the trolling of competitors seems so intense from the True Believers' preferred environments (and yes, that view of Python has been growing on me over the last few years.)