The JVM *could* host a Perl implementation - and do it well!

I started writing this as a response to chromatic's post at his Modern Perl blog. Short version: I think that the VM will be no problem for Moe, Stevan Little's new project to bring a Perl (or dialect) to the JVM.

Overall, I think chromatic's points are very good, and I agree with many of them, especially in the "What Moe Could Produce" section.

But I disagree with one point, in that the JVM has (at least to me) proven that it is an excellent platform for hosting dynamic languages. Well, at least one dynamic language.


I spent a year porting Perl 5 code to Clojure. The first phase of the port was (more or less) a bug-for-bug reimplementation of the architecture of our product, including porting a *lot* of the functionality of Catalyst, and some of Moose.

Doing it this way allowed for some good comparisons to be made between the languages. For example, the Clojure code, overall, wasn't really any more or less readable than it was in Perl, nor was it much easier or harder to "grok". Changing the language and VM while keeping the same overall design didn't make the product any more scalable, and not a *whole* lot more robust, but one thing stood out for me - it was faster.

a lot faster

And yet, IMO, we didn't lose much at all in the way of flexibility, as the Clojure language, despite being Yet Another Lisp Dialect(tm), is actually quite pleasant to work in. Syntax aside, I felt it had a lot in common with Perl, and found that just about any technique or trick I might want in Perl 5 was either available to me or was unnecessary due to the availability of alternatives. Built-in anonymous lists, arrays, and hashes with a concise syntax to use and define them? Check. (in fact, it's '() [] and {}, respectively, with the contents inside the delimiters). Mutability of atoms, data-structures, and objects? Not by default, but you can make them. Even the "object system" has a lot in common with Perl 5. Introspection of *everything*? Symbol-table hacking galore? All that and much more. A very nice toolchain that automates nearly all the drudgery and headaches? Check. Full compatibility and integration with code written in other languages running on the JVM? Wonderfully done. We even added a macro so that regexes felt more like a built-in feature rather than a library.

Only thing missing is an analogue to the CPAN. And I heard that's being worked on...

Compared to Perl, I might complain that Clojure is completely unsuitable for command-line programs. Of course, that's not what Clojure is currently used for (I love leiningen as a build and dependency tool. I *hate* waiting for it to start up...)

Bottom line, I believe that the JVM can handle just about any dynamic language or language construct you throw at it, it's just not suitable for "scripts".

(unless you keep a persistent JVM instance or use something like drip and even then, that seems to me to be a lot of overhead just for scripting)

Anyhow, while I don't agree that Perl is "dead", both Stevan and chromatic make excellent points in their recent talks and posts, and I heartily support any effort that might produce a usable variant of Perl 5 on another VM. I especially think that targeting the JVM is an excellent choice. I've seen a little Scala code, and I think this may just be what I need to start really learning it. That and the fact that some people at my current $work are beginning to use it. I think Moe is feasible. Whether or not it has a shot will depend partially on the community that forms around it, partially on how good and easy whatever "CPAN" might arise is, and partially on how long it takes to get to "production-ready" status.

But that's a topic for another post, and all I have are opinions with nothing real to back them up, which are the kind I tend to keep to myself.


As an aside, a notable issue with Clojure is the density and near-uselessness of the the stack-traces. Nearly as dense as C++ compiler errors with a dozen nested templates and almost as useless as Python stack traces in a Twisted application. Clojure's exception dumps make Moose's dumps look sane. I suspect this is because of Clojure's dynamic nature combined with the backflips needed to make it all work on the JVM, but regardless, it still works wonderfully.

6 Comments

I agree that the JVM can run some languages fast. My hypothesis is that you either work with a platform or you end up working against it, and that the assumptions of the JVM are different from the expectations of Perl 5 or Perl 6 such that you either need a genius willing to perform heroics or you suffer at the gap between the two.

Shirley, you can't be serious.

Current JVMs have fixed heap sizes and, if you're using a decent-sized heap, GC pauses of over a minute. ONE MINUTE OF DOING NOTHING.

And no I'm not kidding. It's called a "Juliet Pause". Nodes get kicked out of clusters because they look dead, then it turn out they're not dead, but it's too late; they've been written off and their data reassigned. Lose-lose.

I use hdfs (great) and hbase and zookeeper (good) daily. The JVM has its place. I've written Clojure, loved it, then hated it. I am not guessing.

I'm only happy that Moe is using the JVM insofar as I still think Topaz may rise again, and I'm giddy that my competition will be stuck on the JVM.

The JVM has been designed with statically typed languages in mind,the same goes for the CLR and that is why the DLR (build on top of CLR) came into existence;to cater for dynamic languages, as well as interoperate with the static ones on the same platform.

Of course dynamic languages could use the CLR, like the first version of IronPython was,but required more effort by the designer because of CLR's design and orientation. As a matter of fact Jim Hugunin creator of IronPython initially started his research on the JVM where he had made Jython
In 8.2. Dynamic Language Runtime Principles
the CLR's shortcomings as far as dynamic languages go are explained and how the DLR became a game changer(which was also designed with enabling scripting capabilities in mind)

With the DLR you don't need a compiler to turn your source into bytecode.
Before the DLR the IronPython engine compiled Python code into IL, but on the other side, IronJS, the port of Javascript to .NET parses the source into its own AST and then transforms it to an Expression Tree or DLR AST. Once this is done, the DLR takes care of compiling it to IL.

The Expression Tree also acts a common language denominator hence making language interop on the platform feasible.

However,performance wise the static languages are still much faster than their dynamic counterparts.

Maybe Perl 5 could look at that direction ?
(of course I don't know if it is a drawback to be tied in a Microsoft platform ?)

Some pointers :

Dynamic Language Runtime Overview
InfoQ- Inside A DLR Language – IronJS
IronPyton

Hi. I don't understand the subject of this post very well. That being said, I don't see mention of recent work being done on the JVM that I believe is relevant to this discussion. So, without further ado: http://jcp.org/en/jsr/detail?id=292 Please note that this has been implemented in Java 8, and beta builds are now available. http://openjdk.java.net/projects/jdk8/

Cheers,
--Dave

Leave a comment

About Hercynium

user-pic I am not the walrus.