Tag Archives: impressions

Perl 6 First Impressions

Perl Camelia LogoStarting at the beginning in Perl6, I had no clue. I only have a slight one now. But I’ll be documenting some of the things I learn in subsequent posts, in case it can help anyone in the future.

This first post will be about initial impressions, coming from someone who knows a bit about earlier Perls, and has held off actually putting Perl 6 into work.

Background Info

Perl now runs via a VM – right now either the standard JVM or a new one called MoarVM (which people seem to like best and is default, and which I like too because it hasn’t hurt me yet).

Perl itself is a language specification. It relies on the Rakudo compiler to implement that language specification and tie it into MoarVM. This is a great separation of concerns — MoarVM can worry about interacting with the operating system, Rakudo can worry about what it needs to tell MoarVM to do and what the heck a Perl coder meant to happen, while Perl itself remains only in the abstract.

Why Use Perl6 when Other Languages Work Great?

For me it was curiosity. I love coding in Perl, for the most part. It’s the most flexible and powerful language I’ve encountered. I’ve been curious about Perl6 for years, but resisted putting any of it into production until recently. There’s something about it now that feels solid and ready. Here are some of the things that feel compelling to me right now.

Close to the OS

One of the several reasons I reach for Perl before any other language is because it runs close to the OS. Perl grew out of shells and shells grew out of Perl. I was worried I might lose this with Perl6. So far, I am very happily surprised. There is much that makes interacting with the shell/OS even easier – things that don’t require finding the module du jour and reading or refreshing up on it. It just flows in and out of the language.

Bondage or Freedom

It’s your choice! Perl has traditionally been very flexible, and many people who like to be told exactly what to do, or like to tell others exactly what to do — these people become easily exasperated by the freedom of expression Perl offers.

Eventually Perl modules were created that acted like tight girdles and cat-o-nine-tails upon those people, to help satisfy them. Now Perl6 has its own build-in dungeon basement!

You don’t have to use it though. But it’s there if you want it, and it’s seamlessly part of everything.

For example, you can enforce variable types if you want to, and a great many of them too, in bizarrely interesting ways. And you can coerce them around. Or you can leave everything all free-form.

You can use positional parameters when calling methods or subroutines, enforce types there too, or use named parameters, or just sloppily slurp in data. (or neatly slurp 😉 )

And there are many ways to die, even in an orderly way with exceptions. And the default error messages are pretty great, most of the time, with calling stacks included by default, without having to use modules.

And control structures… well, there’s a veritable zoo. Or just your standard, well-known tried and true for those who shrink at variety.

Perl is Smart

Perl has never been limited to being discreetly-sized Lego blocks that kids can easily make a toy house from. It can be used that way, of course. And often it is, by people new to the language.

For me, Perl’s greatest strength is that it has always allowed me to work very intimately with the structure, flow, manipulation and presentation of data, in whatever form, as an actual capability built into the language itself — and to accomplish it in ways that are both optimal and intuitive.

These capabilities have only increased with Perl6 as far as I have seen, though some semantics for getting there have changed. But those changes I believe are justified because I can see how they make sense, to give room to other capabilities that have been added, and to provide some clarifications.

In case that doesn’t make sense, one little example is that string concatenation is no longer done with a dot “.”. In Perl6, variables (objects) can have a dot after them to call a method on that object — that could potentially get confused with a concatenation dot. So they’ve made the concatenation into a tilde “~” instead. It actually looks better I think, but it was a nightmare to figure out when first starting to play. I’ll be documenting some more gotchas as I run across them.

BTW – that last change mentioned also influences other things. For example, “$string .= $thing” has become “$string ~= $thing” for concatenation.

What Sucks about Perl 6

Oh my god everything! (I thought at first). I really did. And I kept running into problems and errors that naturally were due to Perl6’s newness breaking it, and not my own ignorance…. but of course, like most ignorance, it doesn’t recognize itself — and it turns out that every time I thought I had found a bug in Perl6, it was really me not understanding how something had changed, and why.

I may run into legitimate bugs at some point though! I’m just now starting to really dive in. But they’ve had a very long time to work through things.

But it does suck that there are odd little differences between Perl 5 and Perl 6 here and there that can cause problems. But that’s the nature of change. So far nothing sucks really, once I move aside my own irritation at having to learn a few new things.

What’s Surprising about Perl 6

What surprises me most about Perl 6 is that Larry and the team have managed to preserve so much of what was truly monumentally great about Perl 5 and bring that into a context that is offering so many conveniences that were previously only attainable by using sometimes kludgey modules.  For example, I love how we handle command line arguments now. I’ll get into that. No more real need for stuff like Getopt::Long for most things.

Also I had heard that Perl 6 takes a long time to start up and actually run something. This is not the case, at least any more. It feels pretty instantaneous so far, and considering that it has the functionality of Moose built in, that’s awesome! 🙂

I haven’t done any performance metrics on it, and don’t really plan to.  Well, maybe. But it has been a lot more fun than I imagined, and I’m actually looking forward to stopping writing this and getting back to more using it.

Another thing that is surprising to me is its handling of numerics — the math is damn good, and you don’t get weird rounding errors from what I’ve seen. Also it has these magical ranges of numbers that can go clear up to infinity, or skip in defined sequences, and has even type testing built in like is this number a prime… ?

What’s surprising is that it feels like it’s a whole magical world again, and one where you can use convention, or establish your own conventions just as easily.

Anyway, I’ll leave this at that. I’ve really only taken the first little test drive, and not put it through an real industrial rigors. That will be coming as I gain deeper familiarity with Perl 6 — which I have decided now, I intend to do.