LWN.net Logo

Perl 6? Yeah, right.

September 19, 2006

This article was contributed by Chase Venters

There are a lot of terms that a project does not wish to be associated with: "bloated", "slow", "insecure", and "archaic" come to mind. Perhaps one of the worst labels a project can receive, though, is "vaporware", a term reserved for projects that consist of nothing but hot air. If you had composed a histogram of the adjectives used by commentators to color Perl 6 whenever it made a news appearance, you might have worried that the developer community believed that the language was either dying, dead, or would be dead on arrival. Beyond the resulting disagreements over predictions of where this language is headed, there were also disagreements over whether the predicted doomsday scenarios would amount to a tragedy.

And who could blame many of these commentators? Perl 5 is now almost 12 years old. In the years that have passed, developers have been wooed by other languages such as PHP, Python, Ruby and Java. Perl 6 has not yet gone gold, despite the fact that it has been on the minds of Perl developers for years.

If Perl 6 is going to win back hearts and minds, it's going to need to be all that Perl 5 was, and more. It must still be the swiss-army chainsaw of UNIX programming. It must remain the glue that holds the Internet together, and it must keep the ability to mow down entire rainforests in 4 seconds. That's a very tall order, but Perl is famous for making hard things easy and impossible things doable.

Radically Different but Radically the Same

Larry Wall, the creator of Perl, intends for Perl 6 to be the community's rewrite of Perl. When the design phase of Perl 6 began, he asked the community for a series of RFCs. Each RFC proposed a new feature or change to the Perl language. When the dust settled, 361 RFCs had been submitted. Larry then began a process of responding to the RFCs in a series of Apocalypses (think "a Revealing"). Each Apocalypse addressed a series of RFCs, rating the presented problem, suggested solution, and finally casting a decision on whether the RFC as a whole was accepted. The Apocalypse documents formed the first official Perl 6 spec.

Perl programmers might worry that a rewrite would create a language incomparable to the one they grew up on; fortunately, that is not the case. In responding to RFC 28 (Perl should stay Perl), Larry agreed not to go raving mad but reminded that Perl is intentionally multi-paradigmatic. I am happy to report that Perl 6 isn't the work of a madman. It's much more of the things some language purists hate, but with half the calories, none of the hacks and a 16-cylinder turbocharged engine.

Here are some of the new concepts developers can look forward to using:

  1. Coroutines are a general case of subroutines that allow you to return and re-enter at a later time. This model is especially useful for state machines.
  2. Lazy evaluation defers work until it is needed, allowing the use of concepts such as virtual infinite lists.
  3. Function currying essentially creates a new function based on an old function by predefining one of its arguments.
  4. Junctions represent many values at once, allowing a test such as if ($variable ~~ any('str1','str2','str3')) { ... }
  5. Hyperoperators, which apply an operation on an entire vector

In addition to introducing new features, the overhaul has corrected many shortcomings:

  1. given is the new, built-in switch statement with the new ~~ smart-match operator for individual cases
  2. Unicode processing is fully supported
  3. Native object support makes classes, roles, methods, and attributes with strong encapsulation and fully object-oriented exception handling a fundamental property of the language rather than a run-time bolt-on.
  4. Parameter passing in Perl 6 supports named and positional parameters and captures, providing all the flexibility of the Perl 5 calling convention, while supporting well-defined interfaces without the need to invoke third-party modules like Params::Validate.
  5. Multi-method dispatch allows these new well-defined interfaces to be overloaded with different versions depending on the parameter signature
  6. Threading, Garbage collection and XS, the system allowing Perl to link other languages, will all receive improvements as well.

But what is perhaps most interesting is what is happening to Perl 6's bread and butter: regular expressions and text handling. It will be possible to use Perl 5 regular expressions in Perl 6, but the system's new syntax features radical renovation. Regular expressions are now called Rules. This system provides named regular expressions with named captures, both of which can be represented and used in object form. Incremental regex matching can be combined with the system's new ability to write LL and LR Grammars directly in Perl 6 to create advanced parsers even more capable and easy to create than those made with the revolutionary lex and yacc tools of yesteryear. And for the fans of the C programming language, Perl 6 provides macro support, in the form of the ability to alter the Perl 6 grammar itself from within your Perl 6 code.

A Tall Order, Toppled

The promise of Perl 6 is not one that everyone expects will be kept. Surveying the extent of the Perl 6 blueprints, many armchair implementors might rate the requisite development effort as one in need of the infinite number of monkeys currently busy at their typewriters with the reproduction of the works of Shakespeare.

The good news is that the insurmountable task of developing Perl 6 is already well underway. Pugs is a project to implement Perl 6 using the functional programming language Haskell. Written by Audrey Tang, the Pugs compiler implements the Perl 6 language specification, giving programmers an opportunity to write real Perl 6 code today. This also allows the language designers to catch and fix any problems with the Perl 6 specification. The Pugs Subversion repository, currently tracking in excess of 12,000 revisions, is also home to a vast collection of example code and nearly 12,000 unit tests. Backends exist to run Perl 6 code natively, inside a JavaScript runtime, inside a Perl 5 runtime, or inside a Parrot runtime.

The Parrot runtime came to life as an April Fools joke in the form of a press release in 2001 that promised to merge desirable properties of Python and Perl. But whatever the original intention of the Parrot announcement may have been, Parrot is a very real software project whose most recent 0.4.6 release offers a common, free software virtual machine that aims not only to support the Perl 6 and Python languages, but also TCL, Ruby, JavaScript and others.

Pugs and Parrot are not complete projects. Neither claim to be the final, standalone implementation of Perl 6. But what we are looking at is clear. One of the most defining characteristics of Perl is that "There's More than One Way to Do It". It is a belief that choice is good and that flexibility is essential. Pugs and Parrot both represent powerful embraces of this ideal. Where Pugs demonstrates the possibility of running Perl 6 code in multiple programming language containers, Parrot demonstrates the possibility of running multiple programming languages in one container.

This flexibility means that programmers most comfortable using Python, Ruby or other languages capable of being compiled to Parrot bytecode can share functions, objects and modules. The famous Perl DBI and many other excellent CPAN modules can be shared amongst these other languages, rather than reproducing similar but incompatible systems time and time again.

Programmer portability is just as important as program portability. Parrot aims to run on as many of the 50 systems supported by Perl 5 as possible. This ensures bytecode produced by Parrot-enabled programming languages will achieve the kind of portability normally reserved for languages with a long and diverse history. Additionally, by providing a free software implementation of a true common language runtime, software projects like Apache that traditionally offered rich access to their internal APIs through projects like mod_perl can do so with an embedded Parrot runtime rather than a specific language interpreter.

It Starts Today

As mentioned, there is no official, production-ready Perl 6 implementation. But interested programmers need not wait for the future. Pugs provides the ability to run real Perl 6 code today. A number of CPAN modules provide Perl 6 technology inside the Perl 5 language. An experimental Perl 6 compiler written in Perl 5 is under development and currently passes about 10% of the Perl 6 test suite. Part of Perl 6 is already written in Perl 6. And an O'Reilly book, Perl 6 and Parrot Essentials, has already been on shelves for two years (during which time the language has, as you might expect, evolved considerably).

These projects won't stop concerned readers from asking "Would the real Perl 6 please stand up?" In truth, the concept of an "official" Perl 6 implementation misses the point. This is best explained by Larry Wall in Synopsis 1 under the "Project Plan" section:

What we can say here is that, unlike how it was with Perl 5, none of these projects is designed to be the Official Perl. Perl 6 is anything that passes the official test suite. This test suite was initially developed under the Pugs project because that project is the furthest along in exploring the high-level semantics of Perl 6. (Other projects are better at other things, such as speed or interoperability.) However, the Pugs project views the test suite as community property, and is working towards platform neutrality, so that Perl 6 is defined primarily by its desired semantics, not by accidents of history.

Lastly, it is expected that Perl 6 will be self-hosting. The compiler for Perl 6 will be written in Perl 6 itself. This implementation effort is already underway in the Pugs v6 repository.


(Log in to post comments)

Perl 6? Yeah, right.

Posted Sep 21, 2006 5:56 UTC (Thu) by moxfyre (subscriber, #13847) [Link]

First of all: Chase, this was an awesome, awesome article. One of the greatest dev articles ever on LWN, I think. Really an excellent and clear summary of the mess that is Perl 6 :-)

I'm a long time Perl hacker, cut my teeth on CGI scripts then worked on a huge variety of text processing utilities at a speech synthesis software company.

But I got around to learning Python a few months ago, and I have to say I was really impressed. I think it's no wonder that developers have flocked from Perl to Python:
* Perl may still have an edge in terms of the sheer number and variety of CPAN modules, but Python is extremely versatile too. There's nothing I've needed to do in the past few months that didn't already have a Python module.
* Python emphasizes a very strong and specific "Pythonic" style, while with Perl it's TMTOWTDI. This makes it *way* easier for me to read someone else's code.

Above all, I find that with Python it's nearly as quick and easy to write a working program as in Perl, but Python makes it a lot harder to write a subtly incorrect program. Perl has a lot of auto-magical stuff and complicated syntax that can be a blessing, but often a curse, for developers and debuggers.

I've gravitated towards using Perl only for quick one-off scripts, and Python for everything else...

Perl vs. Python

Posted Sep 21, 2006 8:45 UTC (Thu) by dion (subscriber, #2764) [Link]

Being an old Perl hand and having just learnt a bit of Python I think Python has weighed orthogonality higher than code readability, just look at lists:

perl lists have: shift, unshift, pop, push
python lists have: pop(0), insert(0, ...), pop(), append()

Having a pop method without a push method ought to be a hanging offence IMHO.

Same thing with sort, to do anything you need to create a lambda and declare parameters, perl is much more straight forward in that regard.

Then are the places where Python just does things strangely, like the "for ... if" construction, which is like map {} grep {} in perl but less general and IMHO uglier.

Python would be a better language if a bit more thought was put into making the language humane, rather than just work.

Oh and just a quick correction Parrot was not started as an april fools joke, only the name came from the joke.

Perl vs. Python

Posted Sep 26, 2006 21:56 UTC (Tue) by tuskentower (guest, #40758) [Link]

You forgot to add Python's block-by-indentation. I was initially excited to hear about Python and even told my wife to skip PERL in favor of Python for her BioInformatics script. Once I saw the block-by-indentation hersey I stayed away from Python.

I write clean code. I don't need the language to force that down my throat.

Perl 6? Yeah, right.

Posted Sep 21, 2006 21:10 UTC (Thu) by swiftone (guest, #17420) [Link]

As a long time Perl programmer, I was happy to see a reappearance of Perl on LWN. Sadly, there is very little here that hasn't been mentioned in any of the other "Perl 6 is Coming!" that have come out since Larry announced that "the effort to write Perl 6 has begun in earnest." in 2000.

2000.

That's 6 years. That's just shy of the time it took to go from Perl 1 to Perl 5.

I dearly love my Perl, and I'll continue to use it for small scripts and helper routines, but I've been waiting for 6 years for it to become a language I could get supported at my workplace, or one that I didn't have to scrounge for jobs for. Meanwhile I'm watching code drones getting solid salaries, support teams, and budgets. What's worse, they're making a bigger impact on the world because of that support.

Sorry Chase, this article hasn't changed anything for me, nor does it say much more than I could find in January (http://www.perl.com/pub/a/2006/01/12/what_is_perl_6.html) or Allison Randall's YAPC::NA 2005 Address (can't find a link) that I was present for.

I love what I see in the Synopses (SP?) but I loved it years ago when I first read them, and I still have nothing to take to work.

I realize I shouldn't criticize, since I haven't contributed myself, but I'd rather not hear about it until there is something finished. After all, that's the best way to avoid a title like "vaporware".

Perl 6? Yeah, right.

Posted Sep 22, 2006 14:44 UTC (Fri) by tjc (subscriber, #137) [Link]

That's 6 years. That's just shy of the time it took to go from Perl 1 to Perl 5.
It's also the length of time that the Algol 68 committee took to go from concept (1963) to implementation (1969). I hope that Perl doesn't fall into the same complexity trap as Algol 68, PL/1, and Ada did, once upon a time.

Perl 6? Yeah, right.

Posted Sep 22, 2006 16:24 UTC (Fri) by amsix_noc (guest, #38927) [Link]

> I hope that Perl doesn't fall into the same complexity trap as Algol 68,
> PL/1, and Ada did, once upon a time.

Ada, oh Ada,
Thy palindromic name
Still haunts my dreams at night...

- SB

Perl 6? Yeah, right.

Posted Sep 22, 2006 14:03 UTC (Fri) by munozga (subscriber, #26290) [Link]

Regular expressions in Perl6 are actually called a 'regex'. A rule, in Perl6, refers to a specific form of a regex.

Link to Synopsis 5 that covers this stuff:
http://dev.perl.org/perl6/doc/design/syn/S05.html

looking forward to p6

Posted Sep 22, 2006 20:05 UTC (Fri) by b7j0c (subscriber, #27559) [Link]

first of all, it is worth noting that perl5 has not been standing still.
since perl6 was announced in 2001, perl5 has seen bug fixes and performance
improvements go into subsequent minor verions. so if you use perl5, it is
still getting better. that said, i am excited about perl6. optional strong
typing, optional haskell-like function definitions, rules (the new
regexes), and better support for concurrency are just a start. and the best
thing is that perl6 will come out with CPAN behind it. CPAN still has no
peer. 2007 is going to be a great year for perl6.

*NOT* looking forward to p6

Posted Sep 23, 2006 5:39 UTC (Sat) by smurf (subscriber, #17840) [Link]

Personally, I am not at all excited about perl6.

If perl5 resembles line noise, then perl6 is line noise at the peak of a solar flare. Just read the synopses for examples of syntax. Lots of syntax. With fine distinctions. Which no non-expert is going to remember.

IMHO, much of that stuff is at entirely the wrong level of abstraction.

I agree that there are nice features (defining new operators, named parameters, multimethods, ...), but they're going exactly the wrong ay about some of them. For instance, this

sub fun (Int $x) { ... }
f( x => 1, x => 2 ); # $x := 2

should throw an error instead. Likewise, defining an infix operator with the same name as a postfix one should be an error -- instead, perl6 will use whitespace to disambiguate them.

Perl 6? Yeah, right.

Posted Sep 23, 2006 9:34 UTC (Sat) by fergal (subscriber, #602) [Link]

And for the fans of the C programming language, Perl 6 provides macro support, in the form of the ability to alter the Perl 6 grammar itself from within your Perl 6 code.

You mean lisp, not C. Perl has had C macros for decades (perl -P). C style macros allow you to stitch bits of text together before they get parsed. Lisp style macros allow you to take parsed code and manipulate it before it gets compiled to it's final form. This is a much safer and more powerful idea than C style macros.

All that said, Perl 6 does not excite me at all, it looks like it will be even easier to do stuff that only 10% or 1% of the perl community can understand.

Perl 6? Yeah, right.

Posted Sep 24, 2006 3:21 UTC (Sun) by chromatic (guest, #26207) [Link]

Isn't the question "How productive is a good programmer with the language?" much more interesting and insightful than "How badly can a barely-trained monkey write code?"

It's not as if there's a shortage of barely-trained monkeys, nor a limit to the damage they can do with *any* language.

Perl 6? Yeah, right.

Posted Sep 24, 2006 5:42 UTC (Sun) by fergal (subscriber, #602) [Link]

Isn't the question "How productive is a good programmer with the language?" much more interesting and insightful than "How badly can a barely-trained monkey write code?"

It certainly is but I'm not talking about badly trained monkeys. The more syntax and features you put in the language, the more I have to learn before I can read "average" code. By "average" I don't mean quality, I just mean the code I'm likely to run across reading mailing lists, articles or CPAN code.

Larry likens Perl 5 to a natural language and talks about how long it takes to become fluent. With Perl 6 it will take longer. I haven't seen the killer features that would make me want to bother to do all that again.

Perl 6? Yeah, right.

Posted Sep 28, 2006 11:41 UTC (Thu) by renox (subscriber, #23785) [Link]

Indeed, frankly in my opinion Perl baroque style is its downfall..
Perl5 is bad and Perl6 will be even worse (still IMHO of course).

Ruby or Python are much easier to learn..

Perl 6? Yeah, right.

Posted Sep 29, 2006 15:30 UTC (Fri) by dmag (subscriber, #17775) [Link]

I agree, it's easy to worry that Perl6 will "Jump the Shark". It's also easy to move to another language. (Ruby is *much* better replacement than Python. Ruby has all of the power of Perl, but with better syntax.) Nobody wants their language to be the next Cobol.

But so far, Perl6 appears to be a good solid upgrade to Perl5. Perl may slow down, but it won't die. Perl6 allows you to write readable parsers because of the Rules engine. Superpositions are an innovative concept allowing any variable can have many values, but code can treat it like a single variable.

As always, choice and innovation are good. Thanks for the article.

Perl 6? Yeah, right.

Posted Sep 30, 2006 9:35 UTC (Sat) by mp (subscriber, #5615) [Link]

From the point of view of an interested programming languages observer, who had, however, never really used Perl, this was an intersting article. Thank you.
But I think it would be even more interesting and useful if the feature lists included links to the relevant RFCs or Apocalypses.

Copyright © 2006, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds