This post got a lot of discussion on Hacker News that you might find interesting.

I’ve been writing a fair bit of Perl 6 lately, and my main takeaway so far is that Perl 6 is fun.

Pretty much everything I love in Perl 5 is still part of Perl 6, but almost everything I hate is gone too.

Here are some of the things that I’ve been having fun with in Perl 6 …

Built-In OO and Types

I really love that I can write this in native Perl 6:

Of course, you can already do pretty much the same thing with Moose in Perl 5, except now I don’t have to debate Moose vs Moo vs Moops vs STOP MAKING SO DARN MANY “M” MODULES!

Roles work just as well with a simple role Foo { ... } declaration.

Multiple Dispatch

If you’ve ever written an API for parsing a text format as a stream of events in Perl 5, you’ve probably ended up with something like this:

And of course to dispatch it you write something like this:

That’s not terrible, but it’s so much more elegant with multiple dispatch in Perl 6. Here’s our listener with multiple dispatch:

given/when and smartmatching

There was an attempt to put this in Perl 5 but it never worked out because this feature really needs a solid type system and ubiquitous OO to work properly.

Smartmatching also dovetails nicely with Perl 6’s junctions:

Easy Threading

Spinning of a few threads to do work in parallel is pretty easy. Just make a Supply and call its throttle method. Tell it the maximum number of threads to use and give it a Routine to do the work.

So Many Little Things

Did you catch that $prog.?update($i) call in the method above? If $prog has the method I’m looking for, the method is called, otherwise it does nothing. If the object wasn’t created, then $prog is an Any object, which doesn’t have an update method.

And I haven’t even had a chance to use features like grammars, built-in set operations, or a native call interface that lets you define the mapping between Perl 6 and C with some trivial Perl 6 code. If you’ve ever written XS you will appreciate just how wonderful that interface is!

Also, the Perl 6 community has been great to work with, answering all my questions (dumb or not), and even improving an error message within about 10 minutes of my suggestion that it was unclear! Of course, the Perl 5 community is pretty great for the most part too, so that’s nothing all that new (although no one can patch anything in the Perl 5 core in 10 minutes ;).

Comments are closed.