Jython vs. Groovy smackdown
by Kevin Dangoor
OK, sorry for the headline. Tim Bray recently wrote a bit about Jython. I agree wholeheartedly about the use of dynamic scripting languages with Java. I also agree that Jython is a very fine product and love the Python language.
But, when looking to do scripting on top of Java, I think Groovy is going to be a great choice. The big trouble with scripting your Java apps in Jython is that you need to make the mental shift over to Python syntax. With Groovy, most legal Java syntax works just fine. So, if the Java-ism for doing something is what comes to mind quickly, you can write it that way. The times when you’re trying to really save on some work, you do things in a more Groovy way.
Jython does have the maturity advantage, as Tim points out. The ability to use premade libraries written in Python or Java is a bonus… just remember, though, that Python libraries tend to be rather, well, Pythonic. This is a good thing, if you’re a python geek like me, but might make things a little less intuitive for people who are used to doing things the Java way.
I’ve been following the discussions on the groovy-user mailing list (and will probably join the JCP list), and I think there’s a good direction there. People are conscious of the tradeoffs between being Java-like, and building conveniences into the language.
Groovy works quite well already. If you haven’t tried it, give it a whirl. Once the Eclipse plugin works in new Eclipse builds and has the spiffy testrunner that I’m used to, I plan to start using Groovy for unit tests. I’ve already found a good minor role for it in the app we’re building as well. So, though I’m a Python fan, I think Groovy is the finer scripting choice for Java.
I don’t really see the point in meing able to ‘script’ java in java. (BTW that’s exactly what BeanShell does, isn’t it?) I know that there is more to Groovy than that, however, I don’t see it as a valid selling point. If I want java, I’ll use java. If I want scripting, I’ll use jython. (I could use Groovy as well, if it were pythonic instead of ruby-ish
but not through the java syntax.)
My only problem with jython is that its built-in types does not integrate really well with java types. (E.g. the other day I used it at a competition to read and write some simple text files and I had to convert the jython list type to java list using java.util.Arrays.)
Actually, that’s my problem with BeanShell… it’s too close to Java. Sure, it’s dynamically typed, but dynamic typing isn’t all that makes Jython or Groovy quicker to write.
I do think that Groovy integrates a little nicer with Java (but not by too much, Jython has good integration).
I don’t view Groovy as Ruby-ish or Pythonic so much as Java-ish. The features that Groovy offers feel like Java extensions, to me at least, rather than a completely different language.
It boils down to the “feel” more than anything. Groovy and Jython have very similar language “features”, but Groovy feels like a better fit when working with Java.
If all you care about is scripting java, then it really does come down to your personal preference. I know jython and I looked at groovy and I didn’t see much that was missing. However, IMHO it is short-sighted to focus strictly on scripting java. Because once you know jython, you also know python. And I’ve found lots of uses for python, and it’s vast libraries, outside of java–utilities, code generation, custom test tools, interfacing to win32 apps via com, etc. But why take my word for it (Bruce Eckel’s “Why I Love Python”): http://64.78.49.204/pub/eckel/LovePython.zip
As for “context thrashing” when switching between languages as your working day-to-day, you get over it–quickly. For me, java and python are a one-two punch. I think java and groovy is also a useful combination, except you’re still stuck with a jvm–while python offers an entirely new tool for your arsenal.
Wisconsin Java User Group meeting
The next meeting of the Wisconsin Java User Group just snuck up on me. The next meeting is on Wednesday, May 19th and it will feature John Carnell. The topic of the meeting is Jython in Action and John will demonstrate how to leverage the Java-based …