Top five scripting languages on the JVM

Groovy and JRuby lead a strong field, with Scala, Fantom, and Jython following behind

Anyone who has followed software development tools during the last decade knows that the term "Java" refers to a pair of technologies: the Java programming language and the Java Virtual Machine (JVM). The Java language is compiled into bytecodes that run on the JVM. Through this design, Java delivers its vaunted portability.

The language and the JVM, however, have been increasingly moving in opposite directions. The language has grown more complex, while the JVM has become one of the fastest and most efficient execution platforms available. On many benchmarks, Java equals the performance of binary code generated by compiled languages such as C and C++. The increasing complexity of the language and the remarkable performance, portability, and scalability of the JVM have created an opening for a new generation of programming languages. These languages lack Java's syntax overload (often referred to disparagingly as its "ceremony") -- that is, the amount of excess code that needs to be cranked out before the code that does the actual work can be written -- but take advantage of the JVM.

[ Eclipse PDT, NetBeans, NuSphere PhpED, and Zend Studio lead a capable field of IDEs for Web developers. See "InfoWorld review: Eight PHP power tools" | With WYSIWYG prototyping environments and preconfigured graphical components, rapid Web development tools can help you build applications faster -- but with less flexibility. See "InfoWorld review: Tools for rapid Web development" ]

In this article, I examine a handful of these languages, comparing and contrasting them, and identifying the needs they satisfy particularly well. I limit myself to the JVM languages that are free and open source. The closed source, commercial world, surprisingly, has few comparable offerings. The one standout is Cold Fusion Markup Language, which is part of Adobe's Cold Fusion Web application development environment.

Technologists differ on what exactly is a scripting language. In its narrowest definition, it's a language that enables the developer to write quick programs. These programs are generally interpreted or semicompiled, rather than compiled in the traditional manner. In choosing the languages for this review, I used a broader definition, which is any JVM language that is simpler to code in than Java. Some are compiled, others are semicompiled, but all are suitable for rapid development. The languages I've focused on are Groovy, JRuby, Fantom, Jython, and Scala. There are a few other candidates, namely Clojure, JavaFX, and NetRexx, which I cover briefly at the end.

The JVM scripting languages today naturally divide into two groups based on their rate of adoption. Groovy and JRuby fall into the popular camp, while the others are niche players -- that is, they appeal to a small community at present. It's important to note, however, that both Groovy and JRuby were also niche players two years ago, so there is no reason to believe that a niche language is relegated permanently to the margins. I believe that the likelihood of emergence favors Scala, then Fantom, and finally Jython. As I explain later, I think Jython's moment in the sun has probably come and gone.

JVM scripting language No. 1: Groovy -- powerful, high-level, enterprise-friendlyJVM scripting language No. 2: JRuby -- a better Ruby than Ruby?JVM scripting language No. 3: Scala -- fast, multiparadigm programmingJVM scripting language No. 4: Fantom -- Java and .Net plus performanceJVM scripting language No. 5: Jython -- Python for the JVM Clojure, JavaFX, and NetRexx

JVM scripting language No. 1: Groovy -- Powerful, high-level, enterprise-friendly Groovy is an object-oriented language that is compiled to bytecode. Its principal syntactical trait is its close similarity to Java, but with much of the clutter removed. Java developers can quickly come up to speed on Groovy, and in fact, the Groovy compiler happily accepts pure Java syntax, allowing Java developers to transition to a scripting language without having to learn an entirely new syntax.

One of the many aspects of Groovy that simplify the code is the use of duck typing. This term refers to the ability of the language to infer the type of a variable without having to be told explicitly by the developer. For example, Groovy can examine a variable's initial use and determine that it's an integer, a string, or so on. Programmers are free to provide this information or simply let Groovy work it out.

Groovy was one of the first scripting languages to offer another feature, called closures, which Java developers unsuccessfully pressured Sun (and presumably now Oracle) to deliver. Closures enable developers to specify a small piece of code as a stand-alone entity and tack it on to other programming operations. This enables great concision in describing program function and, in other languages, can provide a means to create functions as objects that can be passed as parameters to other functions.

Groovy also provides high-level constructs for handling standard tasks such as string processing, consuming or generating XML, unit testing, and so on -- all of which can save developers significant time. In fact, one of the early use cases for Groovy took advantage of its high-level syntax and testing support to quickly knock out unit tests for Java code.

Groovy has a unique history that highlights some of the vicissitudes of the open source world. The project was started up in 2003. The founders subsequently moved on to other projects, and at various times disparaged their original creation. Even without them, though, there was enough interest for the community of contributors to keep Groovy moving forward. The project was then taken up in earnest by Guillaume Laforge, a developer from France, and under his leadership enjoyed a renaissance. A leading Web framework, Grails, was built using Groovy and eventually tool companies started supporting Groovy in their IDEs and other developer products.

Laforge and the developer of Grails, Graeme Rocher, now both work for SpringSource, a division of VMware. This corporate backing might suggest that Groovy's future is assured. But while the language's popularity is on the rise, it suffers from a long-standing weakness that is slowly being addressed: a slow runtime. Despite the JVM's optimized performance, several Groovy features exact a high cost. Various efforts are under way to substantially change these features or diminish their performance impact.

JVM scripting language No. 2: JRuby -- a better Ruby than Ruby? JRuby is a Java port of the Ruby language. Ruby itself is a scripting language developed in the mid-1990s in Japan, where it has enjoyed wide adoption. The language was a sleeper in the United States and Europe until its killer app, Ruby on Rails, was released in 2004. Using a set of conventions that made assembling the various parts of Web applications much easier, Rails was quickly put to use in developing websites for small and medium-sized businesses. The popularity of Rails led to an explosion of interest in Ruby.

The Ruby language has many of the features I've described in Groovy, but it uses a terser syntax -- allowing developers to get more work done per line of code written. The big problem Ruby faced was performance. In multiple benchmarks, it came in last or close to last when compared with all other languages. This spurred numerous competing projects to rewrite Ruby. Of these, the most successful has been JRuby.

The JRuby project was started in 2001 as a straight port of Ruby code. By 2007, the project -- now under the control of a pair of engineers at Sun, Charles Nutter and Thomas Enebo -- could run Ruby on Rails and delivered performance comparable to non-Java Ruby. Since then, the developers have moved to Engine Yard, a commercial host for Ruby on Rails, where work on JRuby has continued apace. In the meantime, Ruby released the much faster 1.9 version. According to Nutter, JRuby's performance is now comparable with this release.

Like Ruby, JRuby is attractive to developers for more than its very high-level syntax. It also enjoys a pure object-oriented implementation (unlike Java, where some entities are objects and others are not), closures, duck typing, and an interpreter. The use of an interpreter means that you can move from coding to execution immediately. What JRuby has that Ruby lacks are the vast libraries of the Java platform. Ruby has many good libraries, but they are neither as numerous nor as widely used as the standard Java libraries.

The access to Java's runtime environment and libraries is a crucial aspect in determining JRuby's future. Ruby has not broken into the enterprise in a big way. JRuby may well be its ticket there. JRuby has the advantage that enterprises are already comfortable running apps on the JVM, whereas the native Ruby virtual machine is an unknown element whose peculiarities are not known to stokers in the data center. In addition, because of the integration with Java apps, companies can adopt Ruby via JRuby and still leverage previous investment in Java software.

Whether enterprises will favor Groovy or JRuby depends entirely on the needs felt inside the IT development center. Both solutions work well, are supported by paid developers (rather than by volunteers), have growing support among tool vendors, and are likely to be around for a while, delivering working code quickly.

Niche languages The following three languages are not as established as Groovy and JRuby, but they have the elements that could bring them success in the next few years. Even if they don't reach that level, they have enthusiastic supporters who are likely to keep the languages alive in diverse programming niches.

JVM scripting language No. 3: Scala -- fast, multiparadigm programming Scala (pronounced "scah-lah") was originally developed as a research language in 2003. It is often described as a multiparadigm language because it combines elements from different programming philosophies. At its core it is a pure object-oriented language (that is, everything is an object) with functional capabilities. Functional, in this context, refers to a programming style popular in academia that favors the use of functions with no side effects (functions that do not alter the state of variables or other functions), the use of first-class functions (functions become objects that can be passed to other functions), and to the extent possible, the use of constants over variables. The last preference might sound peculiar, but it's already found in many languages, including Java. For example, strings in Java cannot be modified. Any attempt to change an existing string results in the creation of a completely new string.

Functional programming has been a favorite area of research, and Scala might be a vehicle by which it enters the mainstream. Its big advantage over traditional programming approaches is that it greatly facilitates parallel programming -- the ability to have multiple portions of a program executing simultaneously. As multiple cores become the norm in modern processors, parallel programming represents an excellent way of exploiting the full capabilities of the hardware. To this end, Scala is unique among the languages for the JVM in having actors -- another parallel programming construct -- built into the language. (Fantom has actors as an add-on. The difference is small, but important for some developers.)

Scala enjoys a singular advantage over the other languages reviewed here: performance. The language is compiled to optimized bytecode and runs essentially as fast as native Java. The remaining languages are either somewhat or very far behind Scala in execution speed.

Scala does have shortcomings, however. The first of these is sometimes opaque syntax. Every language can be used to generate impenetrable code, but it is easier to do so in Scala. The second problem is one of binary compatibility. The maintainers of Scala have several times released new versions that are not binary compatible with previous versions. This is a huge obstacle to widespread adoption, certainly among enterprise developers, who will find no enjoyment in recompiling existing code to be able to work with more recent code. Nonetheless, good tools for Scala have emerged, and the community of users is active and enthusiastic. I fully expect Scala to be in the top tier of JVM languages within a couple of years.

JVM scripting language No. 4: Fantom -- Java and .Net plus performance Fantom (formerly called Fan) is unique among the languages discussed here in that it generates bytecode at runtime for either the JVM or Microsoft's .Net platform. The language is object-oriented with many of the same features described previously for Groovy and JRuby, except that integration with the Java libraries is not as seamless: A special interface is required to interact with existing Java bytecode. Fantom makes up for this shortcoming in part by having extensive libraries of its own.

The language follows the vision of its designers, Andy and Brian Frank, who originally wrote it to develop a large package of real-time software for one of their clients. Their vision, much like that of Groovy's and JRuby's designers, is to make coding easier. They've eliminated a fair amount of ceremony, but pushed ahead into new areas to make some interesting choices.

For example, all integers and floating-point values are 64 bits wide. This means that for all intents, the results of arithmetic operations cannot overflow the size limits of the resulting field. (This problem can lead to hard-to-find bugs that can have disastrous results on calculations.) Fantom also includes built-in support for concurrency (parallel programming) via actors -- a trait shared by only Scala in this roundup. The libraries have been thought through to follow a different model than the standard APIs from Java and .Net, which are anything but orderly. As a result, it's easy to anticipate which API is needed for a specific function and where it can be found. Becoming productive with Fantom is made even easier by the excellent documentation at the Fantom website.

Like many of the niche languages, Fantom suffers from limited support via external tools. Its only IDE support, for example, is a single plug-in to the NetBeans product. This is likely to change as the community for Fantom grows and its unique design and cross-platform characteristics become more widely known.

JVM scripting language No. 5: Jython -- Python for the JVM Jython, or what was originally JPython, was one of the first scripting languages to be released for the JVM. Its intent was to provide a Python implementation for the Java platform. In this respect it mostly succeeds, as it implements all but a small portion of the Python language. Python itself was one of the original scripting languages (along with Perl). It has retained its popularity over the years as one of the best all-purpose languages, and it is widely used inside of Google, which employs its original developer, Guido van Rossum.

Jython initially received a warm reception, but after its principal developer, Jim Hugunin, left the project to work at Microsoft the language began to flounder. (At Microsoft Hugunin wrote IronPython, a version of Python tailored to the .Net CLR.) Jython then went through a succession of lead programmers; the project essentially stalled from 2005 to 2008, leading to a dissipation of the community. In the interim, other scripting languages for the JVM, notably Groovy, gained traction and Jython was never able to regain momentum.

The Jython language, however, found its way into commercial applications, and it is one of the two officially supported scripting languages in WebSphere Application Server, IBM's commercial Java EE product.

Clojure, JavaFX, and NetRexx Clojure, JavaFX, and NetRexx are likely to face a more difficult path breaking into the enterprise than those previously discussed. These languages are not inherently flawed, but they either appeal to very small communities (Clojure and NetRexx) without having notable business-oriented features or (in the case of JavaFX) face intense competition from other languages. Predicting the future path of any language is a fool's errand, so I could well be wrong, but I suspect many language cognoscenti would agree with my projection.

Clojure is a purely functional language that is a dialect of Lisp; syntactically, it sits between Common Lisp and Scheme (the two main variants of Lisp). Like Scala, it has built-in support for concurrency that enables the clean separation of immutable and mutable functions. Unlike all the other languages mentioned here, however, it is not object-oriented.

JavaFX is a Java platform and scripting language brought out by Sun during the last two years to facilitate the development of rich Web applications. While successful at delivering this functionality, it has not found widespread acceptance. Despite this, when Oracle purchased Sun, JavaFX was specifically called out by Larry Ellison as one of the key technologies he would continue to invest in.

Finally, NetRexx was the original scripting language for the JVM. Developed by IBM, it is based on the high-level Rexx language. Although IBM made NetRexx available for free, it was never open sourced. Rumors that IBM will open the source have swirled throughout much of its lifetime, but there has been little confirmation of that. Despite being a remarkably well-thought-out scripting idiom -- that can be either compiled or interpreted -- NetRexx has languished. IBM updated it exactly twice since its release in 1997, and as a result, it no longer has an active user base.

Also on InfoWorld:

How HTML5 will change the WebHTML5 will spawn richer, more sophisticated websites while also easing development. Here are nine ways the impact of HTML5 will be feltWhat to expect from HTML5Support for the next generation of HTML is already appearing in today's browsers and Web pages. Are you ready to take advantage? InfoWorld review: Virtualization for development and testVMware, VMLogix, Surgient, and Skytap lab managers ace virtual machine configuration, deployment, and teardown, with some key differences in features and easeInfoWorld review: Tools for rapid Web developmentWith WYSIWYG prototyping environments and preconfigured graphical components, rapid Web development tools can help you build applications faster -- but with less flexibilityInfoWorld review: Eight PHP power toolsEclipse PDT, NetBeans, NuSphere PhpED, and Zend Studio lead a capable field of IDEs for Web developers InfoWorld review: Climb aboard Ruby on RailsThe InfoWorld Test Center sifts through nine Rails IDEs and editors to help you choose the tools to suit your development needs

This article, "Top five scripting languages on the JVM," originally appeared at InfoWorld.com. Follow the latest news in software development and Java at InfoWorld.com.

Read more about developer world in InfoWorld's Developer World Channel.

This story, "Top five scripting languages on the JVM" was originally published by InfoWorld.

What’s wrong? The new clean desk test
Join the discussion
Be the first to comment on this article. Our Commenting Policies