Wednesday, April 3, 2013

Why I use Perl 6

I'm one of those mythical beasts that you've been hearing about for years but have never actually seen -- I am a Perl 6 user.  And much like the hidden Bigfoot of the northern forests, I'm kind of a lurker.  But I do exist, and the time has come for me, at long last, to delurk.

Why now?  The main reason for this is that there is finally an implementation that "just works", Rakudo.  Sure it's still too slow, but most of the dreaded "Not Yet Implemented" errors have faded away.  The module ecosystem is starting to pick up steam, even if it still tiny.

And, coding in P6 is fun.  While at it's heart, everything is an object, Perl doesn't force you into any one paradigm.  If you want to see if a variable is defined, you can use functional (defined $a), object-oriented ($a.defined), or even smart match against the defined property ($a ~~ :defined).  This philosophy runs throughout the language, yet everything works together seamlessly.

And when it comes down to it, Perl 6 is easy to look at.  I've even heard beginners say it was a "beautiful language".  This is not exactly Perl's reputation, but it's true.  Sure, you can still write obfuscated spaghetti code if you want -- we're not talking about Python here -- but it's easy to avoid doing so.  Regexes and grammars are actually readable now, and far more powerful than in Perl 5.  Backslash hell is gone.

Here's a quick example.  In bit of code I ported from Perl 5, I had to turn a path like "././foo/bar" to "foo/bar".  In Perl 5, we have this:
    $path =~ s|^(?:\./)+(?=[^/])||s;
Okay, a strange looking regular expression, but I've seen worse.  But now in Perl 6:
    $path ~~ s/^ './'+  <?before <![/]> >//;
The major difference is that you can tell what it does at a glance without first putting on your robe and regex wizard hat.

The end result is that when I see a piece of new Perl 6 code, it takes me very little time to figure out what it actually does.  I certainly can't even come close to that speed in grokking C++, and even Perl 5 seems like a storm of pointy arrows and curly braces when OOP is involved.

Finally, the community is amazing.  They're not a large group, but they are an active one.  Sometimes, you can report a bug, and it gets a patch 15 minutes later.  Other times it's joking about horse meat on the IRC channel.  But always, they're welcoming to newcomers, encouraging people to play around, send in bug reports, and write code.  They're the kind of people who make one want to delurk.

Perl 6 is powerful, easy to read, adapts to your style, has a friendly community, and most importantly is fun.  Even if it's not "done", I got tired of waiting for Christmas and opened my presents early.  And inside, I found a perfectly usable language.

No comments:

Post a Comment