Which is better, Perl or Python?

Quora Feeds

Active Member
Joe Pepersack

Perl is better.

Perl has almost no constraints. It's philosophy is that there is more than one way to do it (TIMTOWTDI, pronounced Tim Toady).

Python artificially restricts what you can do as a programmer. It's philosophy is that there should be one way to do it. If you don't agree with Guido's way of doing it, you're sh*t out of luck.

Basically, Python is Perl with training wheels. Training wheels are a great thing for a beginner, but eventually you should outgrow them. Yes, riding without training wheels is less safe. You can wreck and make a bloody mess of yourself. But you can also do things that you can't do if you have training wheels. You can go faster and do interesting and useful tricks that aren't possible otherwise. Perl gives you great power, but with great power comes great responsibility.

A big thing that Pythonistas tout as their superiority is that Python forces you to write clean code. That's true, it does... at the point of a gun, sometimes at the detriment of simplicity or brevity. Perl merely gives you the tools to write clean code (perltidy, perlcritic, use strict, /x option for commenting regexes) and gently encourages you to use them.

Perl gives you more than enough rope to hang yourself (and not just rope, Perl gives you bungee cords, wire, chain, string, and just about any other thing you can possibly hang yourself with). This can be a problem. Python was a reaction to this, and their idea of "solving" the problem was to only give you one piece of rope and make it so short you can't possibly hurt yourself with it. If you want to tie a bungee cord around your waist and jump off a bridge, Python says "no way, bungee cords aren't allowed". Perl says "Here you go, hope you know what you are doing... and by the way here are some things that you can optionally use if you want to be safer"

Some clear advantage of Perl:
  • Moose: postmodern object system for Perl. Declarative programming FTW.
  • One liners. Perl has a whole set of shortcuts for making it easy to write ad-hoc scripts on the command line
  • Speed. For most tasks, Perl is significantly faster than Python
  • Regular expressions are a first-class datatype rather than an add in. This means you can manipulate them programatically like any other first-class object.
  • Power. You can do things in Perl that are either much harder, or prohibited, in Python. For instance the <> operator... this lets you trivially deal with the complexities of opening files from the command line and/or accepting streams from pipes or redirection. You have to write several lines of boilerplate Python code to duplicate the behavior of Perl's while (<>) { ... } construct (or even more trivially the -n switch, which automatically wraps your code with this construct).
  • No significant whitespace. If your formatting gets mangled (by, say, posting it to a web forum or sending it in an email that munges whitespace), the meaning of your code doesn't change, and you can trivially re-format your code with Perltidy according to whatever coding style you define. You can format your code as to what is most clear in context, rather than having to conform to an arbitrary set of restrictions.
  • Postfix notation. This can be ugly and is easily misused, but used with care it makes your code easier to read, especially for things like die if $condition or die unless $condition assertions.
  • Sigils. It's a love it or hate it thing, but sigils unambiguously distinguish variables from commands, make interpolation effortless, and make it easy to tell at a glance what kind of variable it is without having to resort to some ugly hack like Hungarian notation.
  • Inline::C and all of the other Inline::* modules). Yes, you can write Python extensions in C but Inline::C makes it effortless.
  • Pod is vastly more powerful than Docstrings, especially when you throw in the power of something like Pod::Weaver to write/manipulate your documentation programatically.
Advantages of Python
  • JVM interoperatiblity. For me this is huge. It's the only thing that Python does better than Perl. Being able to write code that runs in the JVM and to work with Java objects/APIs without having to write Java code is a huge win, and is pretty much the only reason I ever write anything in Python.
  • Learning curve. Python is easier to learn, no denying it. That's why I'm teaching it to my 12 year old son as his first programming language
  • User community. Python is more popular and has a larger active user community. Appeal to popularity is a fallacy, but you can't just dismiss mindshare and 3rd party support either.


See Questions On Quora

Continue reading...
 
Similar threads
Thread starter Title Forum Replies Date
R Study Buddy Learn Python together Study Buddy 1
D PYTHON Q&A 0

Similar threads

Top