[Update 2015-10-18: Now that Perl6 has shipped, this article is less relevant. The point, however, is that shipping "good enough" is better than not having anything available. That's always true.]
In all the time I've been waiting for Perl6 I learned Python and, guess what? I like Python better.
I'm a big fan of Perl. I have been since 1991, Perl 4.032. That was 19.5 years ago. Back then learning perl was "radical" and "fringe". Backk then it wasn't acceptable at most companies to use Perl. Since then perl was gone from being revolutionary to accepted broadly. Initially it was mostly used by sysadmins but the invention of the web (and therefore CGI scripts), saved it. Prior to this there wasn't much need for heavy string processing (awk was sufficient) or database connectivity (who could afford $50,000 for Oracle?). However with Perl's CGI module and MySQL integration using Perl became "obvious". Heck, you might say that "CGI saved Perl from irrelevance". I was proud to be an early adopter of Perl. Like the apes that learned to use tools before the other primates, it gave me an evolutionary advantage that was undeniable.
Perl4 was good. Perl5 was great. There were 3 things I wanted in Perl6: Cleaner OO support, cleaner grammar, and the third thing? Well, I wanted it to ship.
I'd like to say, "I gave up waiting and learned Python instead" but the truth is that I took a job that was Python-centric, not Perl-centric. At Google we have one official compiled language, one official scripting language, and one official UI language. Yes, other languages are supported in some way or another, but sticking with "the big three" meant support libraries, tools, and an easier way to find collaborators. Sadly the scripting language of choice was Python, not Perl. So I learned Python.
Python has a very clean object model. It has a consistant grammar. And that third thing I wanted? Yes, it's shipping.
Being a Perl Patriot meant resisting Python at first. However now I have to admit that in the last 2 years (and mostly the last year) I've written a lot of Python. In my entire career I've written more perl "quick scripts" (1 to 5 line single-purpose or single-use scripts) but I've now written more lines of "big programs" in Python than in all my Perl experience. (that's more of a comment about how few large programs I'd written in Perl, I guess :-) ).
What I like about Python is:
There's one way to do things. Code becomes a lot cleaner when there is one obvious way to do things. In Perl there are many ways to do things... having some ability to be creative is nice; have too much is stifling. Imagine being at a doughnut shop with 10,000 choices. It's confusing. Now go to a doughnut shop that specializes in chocolate cream filled. Sure, they have others in case you really want a cruller, but you know that the obvious choice (their speciality) is the way to go.
It is readable. It is so readable that often guessing how something might be done is the right way to do things. Here are some examples:
- Does an element exist in a hash (Python calls them 'dicts'): myelement in myhash
- Does a substring exist in a string: 'substring' in string_variable
- Having actual boolean values True and False means I can type "x = True", which is much more readable than "x = 1" (which could mean I want the integer that comes after zero and before two).
Parameter passing is awesome. You can easily set default parameters, names parameters, etc. Yes, Perl can do that now but it is cleaner in Python. Also if someone passes 2 named parameters and 2 unnamed parameters there is a clear order to where those unnamed parameters should go.
I'm in love with None. Yes, Perl has "undef" but it isn't used much. In Python a variable can be equal to None, which is different than zero or not defined. I can default a parameter to None, and take action "if x is None". (that's valid Python. "is" is like equals, only better)
"Batteries included". CPAN is nice but it is stifling to have to decide between 3 different modules that do the same thing. Python has one awesome library for URL manipulation, for one awesome library for file handling, and so on. I'm enjoying how the web framework Django has enabled me to write some really nice, simple, web apps without a lot of code. (I hear Ruby-On-Rails is better but both Rails and Django seem to be better than anything I saw in Perl).
The object model is very easy to work with. With Perl I was confident in using other people's object-oriented modules but fretted about writing my own. With Python it is much clearer to me how things work and why. Since everything is an attribute, I can even monkeypatch objects with confidence.
No interpolation of strings. If you want to format something, there is a great formatting system which is highly optimized.
The "Perl datastructures cookbook" is awesome. You know what's more awesome? Not needing it. In Python data structures make sense so you don't need a secret decoder ring to use them.
Unicode support is really good, and in Python3 is the default (want an old-style string? use a bytearray).
Immutable data types. At first I was confused. "What do you mean I can't edit a string? I have to change it while copying it?" Oh, now I understand! This simplifies so many other things and permits optimizers to really dig into your code. Cool.
What do I dislike about Python? I don't like that to use regular expressions I first have to "import re", but then the regular expression stuff has a lot of useful features. I don't like that I can't write one-liners, especially since I use to use Perl's "-a" and "-n" options a lot. I don't like Python3's ".format()" system, and hate that they are deprecating "%".
When I've made this points in conversations people often think I mean that "Python is what Perl6 should have been". I don't mean that at all. Python is very different than Perl. However, I'm more happy with Python than I am with Perl at this point, and by the time Perl6 is shipping and (hold your breath) main stream I'll have many years of using a language that gives me the benefits I was looking for.
And just to reiterate... my favorite feature is: it's shipping.
Update: 1pm: Fixed some typos.
Update2: 1:01pm: Devdas Bhagat tweeted: "Most of the Perl gripes appear to be a few years old. Perl has backported most of the stuff you want from P6 to P5." I reply: Many fine features have been backported. I'm more concerned with unfixable things like readability other things from my list.
> Perl5 was great. There were 3 things I wanted in Perl6: Cleaner OO support, cleaner grammar, and the third thing? Well, I wanted it to ship.
Don't miss Modern Perl http://www.onyxneon.com/books/modern_perl/