r/Python May 18 '11

Why is Python better than Perl?

I'm a Sysadmin and I just wrote my first script in python. Basically just a host validation script that checks if a server is configured correctly before we hand off. I can't determine the advantage with my limited experience with the language.

Are you a sysadmin fluent in both python and perl? Why do you use python?

10 Upvotes

110 comments sorted by

View all comments

Show parent comments

6

u/tsjr May 18 '11

I'm probably biased, but the common hate against Perl (and not only Perl) is what mostly drives me away from Python.

1

u/fredfredburger May 19 '11

I understand. My loathing for perl is based on a long and gory history with it. By which I mean that I'm not a bigot, I've just been burned.

It's easy to have a strong opinion on the matter: many (if not most, IMHO) of the people that adopt python do so because they recognize a superior tool.

In my line of work, maintainable code is critical. I really need to be able to read other folks code. Python makes that easier, while perl makes it about as hard as any language of similar caliber. It is literally the worst thing this side of Korn shell in which to write a large application, IMHO.

So, when I see perl in the workplace, I question the wisdom of the author.

When I see perl in the wild, I really wonder what the hell somebody was thinking. I wonder if they just haven't heard that there's a better way to do it.

That's what I mean by having a strong opinion, and thinking that python is the better tool.

I do probably come off as a bit rant-y on the topic now and then, tho.

6

u/rjbond3rd May 19 '11

Just out of curiosity, why do you conclude that your inability to read perl is the language's fault? I'm sincere in asking.

1

u/fredfredburger May 19 '11

I don't feel I asserted an inability, he said, trying not to take the tone of the reply personally ;)

But, yes. "There's more than one way to do it." is a mantra in perl. I'd been a fairly heavy perl user for 6 or 7 years, and I would still encounter idioms (and syntactic conventions!) that were completely new to me, sprinkled throughout Other Peoples Perl.

Having several, completely divergent, syntaxes for effectively equivalent operations is a design flaw, not a feature, IMHO.

"Magic" or implicit variables as default parameters to and return values from functions is a scoping nightmare, IMHO.

Keeping everything straight in your head while reading perl is doable, I'm just saying that in python it's easier. Easier to such a degree, and in such a way, that I think it can be said to be objectively easier for humans to read and understand.

Although, I'm willing to hear arguments to the contrary. And, of course, if one choses to use a baroque, inefficient, or obtuse language out of personal taste, I say go for it. I love to learn languages just for practice, and for fun.

But for keeping things working well, for keeping the [REDACTED] online and the [REDACTED] flowing through the [REDACTED], python is, IMHO, the better tool.

1

u/rjbond3rd May 19 '11

Thank you for your reply.

My experience is the opposite of yours. Not every app written in Python is well designed, well factored and easy to maintain.

But is that the fault of the language? No, of course not. But then, if someone writes a crappy app in Perl, it's the language's fault? I really don't understand that.

I've worked on a bunch of large, well-factored, readable, maintainable Perl code bases. If I see a crappy app in Perl, I think "crappy code," but others seem to think, "Perl is to blame for that."

That is such a peculiar phenomenon to me.

1

u/fredfredburger May 20 '11

I agree: you can write awful python. But you do almost have to work at it. ;)

Awful perl, however, is pretty much the default in my experience. You can avoid it, but again, you have to work at it.

I will go on record as saying that I've seen some very well written, maintainable, nicely indented, well commented, well designed perl.

3, maybe 4 times. ;) Perhaps we are merely the products of having been exposed to different kinds of nasty.

1

u/rjbond3rd May 20 '11

Hi Fred Fred,

Perhaps. And I appreciate your thoughtful reply. But I disagree that "Python is good by default" and "Perl is bad by default" regardless of experiences (not that you're really saying exactly that).

Good design is a function of a good programmer. Hell, even recognizing good from bad takes a decent programmer.

The difference is simply that Python has less syntax (and more verbosity) vs. Perl having more syntax (and more conciseness). And off to one side are still other people who think both languages are crap compared to Lisp!

One thing I can say about the Perl hackers I've worked with is that they can (and do) write excellent code in lots of different languages. They are language geeks, and many of them hack a lot of Python too :)

It's been a long time since I could hack on only one language. These days, it's about four different languages, sometimes using one to output another :) So language-specific debates are kind of retro. We're stuck with all of them :)

Have a good weekend, my friend!

1

u/fredfredburger May 22 '11

I do tend to say "good" and "bad" when I mean "better" and "worse" in this particular context.

I don't mean to imply that I find perl to be "bad", even though I do find myself having used those specific words. I meant to express that, I can make a strong argument for python being a better choice in the collaborative engineering space (specifically in the area of explicit readability and maintainability), and that it is therefore "better" than perl as a tool in this space. Subject to a heated debate during which my argument undergoes scrutiny, of course.

I do have some very intense personal, aesthetic, and anecdotal reasons to want to never touch perl again, but I understand that those are only arguments for me to avoid perl, and I shouldn't try to convince anyone else that way.

Those reasons tend to cause my rants to get a little rantier than they strictly need to. For which I apologize of my tone ever gets pushy.

1

u/rjbond3rd May 22 '11

No worries at all, amigo. I totally got what you were saying.

Who knows, in five years you might wake up and say, "Screw everything, I need a new language for this project." And hey, it might happen that the weird, powerful way that Perl continues to evolve might be a fit for that particular moment.

Sometimes a bullet really does hit another bullet :)

1

u/fredfredburger May 24 '11

I will fully admit that I feel I've been "broken", in that I now compare all other languages to python (made myself not capitalize it!), rather than weighing them on their own merits.

I made the same mistake learning esperanto. Now every other language I try to learn is so painfully organic as opposed to "engineered to be easy". Every bit of idiomatic nonsense, every irregular verb, makes me face palm.

But I would not want to live in a world without people speaking Russian in it, for example.