BeanShell: groovier than Groovy

Recent blogs calling Groovy the "sleeping giant" overlook a nimble alternative. With its uncluttered design, mature code base, small size, well defined semantics, dynamic language features, and JSR 274, BeanShell looks way groovier than Groovy.
Written by Ed Burnette, Contributor

Richard Monson-Haefel posted a blog entry recently called "Groovy: The Sleeping Giant". In it, he says that "dynamic programming" is the wave of the future, and that Groovy has the most potential largely because it's a "standard" (he means it has a JSR). He writes:

Companies will understandably be more comfortable adopting a language that has been standardized via the same process that standardizes J2SE and J2EE than a language that is not. Right or wrong, the powers that make decisions look to standardization as a litmus test for acceptance and usage.

Besides being a proposed JCP standard, Richard says it uses much of the same syntax as Java, and  has dynamic language features like dynamic types, mixins, and closures.

Yesterday Grails developer Graeme Rocher posted "Groovy: The Sleeping Giant, an Elaboration". As you might expect, he agreed with most of Richard's points. Plus he adds a few of his own about Meta-programming, builders, closures, object orientation, and of course, Grails. Graeme writes:

So there you have it, Groovy has had its problems, and the FUD that has been spread hasn't helped. But, Groovy is still young, 10 years younger than Ruby in fact, and a fantastic amount has been achieved for it to be where it is today. I look forward to the upcoming release of Groovy 1.0.

What he's talking about is actually Groovy's second version 1.0. Trying to "standardize" the language threw it's development cycle completely out of whack. The first 1.0 beta was in May 2004, nearly 2 years ago. But before it could be released, the JSR was started, more developers were added, and they a new parser and changed major parts of the language. And changed. And changed. I followed the mailing lists for a while but eventually had to drop out because I couldn't take the endless discussions about the proper way to do closures and arguments about scoping. That's not to mention all the weird things they had to do to Groovy to support optional parentheses, optional semicolons, and so forth. If the result bears any resemblence to Java, it's about the same resemblence that Java bears to C or Algol-60.

Instead of Groovy, I recommend looking into the BeanShell language. It's also the subject of a JSR, if that's important to your management. Unlike Groovy, however, they're not trying to standardize something that is a work in progress. And it's definitely not being defined by a committee. From the web site:

BeanShell is a small, free, embeddable Java source interpreter with object scripting language features, written in Java. BeanShell dynamically executes standard Java syntax and extends it with common scripting conveniences such as loose types, commands, and method closures like those in Perl and JavaScript.

Like many great projects, BeanShell is the brainchild of a single person. Pat Niemeyer, author of the popular O'Reilly book "Learning Java", has been working on it for about 7 years. He even included it with his book as an example. BeanShell is used in NetBeans, and also there are some Eclipse plug-ins available for it. For example, Werner Schuster just announced a plug-in called EclipseShell that lets you edit and run scripts inside Eclipse, even prototype plug-ins and dynamic GUIs.

One thing I really appreciate about BeanShell is that it's tiny. The core interpreter is only 143K. By contrast, Groovy's embeddable jar file is a hefty 1.7MB. That's over 10 times larger! Even with all the bells and whistles, BeanShell only takes about 280K.

Another big advantage of BeanShell is that you can take any regular Java source and run it directly with BeanShell. Then gradually you can get used to a more dynamic style like:

add( a, b ) {
   return a + b;

foo = add(1, 2); // 3
foo = add("Oh", " baby"); // "Oh baby"

With its uncluttered design, mature code base, small size, well defined semantics, dynamic language features, and JSR 274, BeanShell looks way groovier than Groovy.

Editorial standards