views:

2587

answers:

6

Why would I choose to use Groovy when I could use Jython or Jruby? Does the language provide any inherent advantages to make up for the fact that Jython and Jruby skills are applicable to their parent languages outside of the JVM?

Keep in mind that I purposely keeping this question generic, but if there are any advantages that exist in a particular domain, please don't hesitate to describe them.

EDIT
To clarify, If I write some code in Jruby, I can now, in some cases, move that code outside of the JVM if need be, or at the very least I have gained a better understanding of Ruby. Whereas Groovy skills are applicable only when using a language that just exists inside the JVM. Jython and Jruby have this built in advantage, what does Groovy have to make up for this disadvantage?

If Groovy doesn't have any advantages that you've found, and you would suggest just using Jython or Jruby, let me know.

Edit 2
Thanks everyone for all the answers, most of them make the same point, Groovy integrates slightly better with Java then Jython or Jruby.

Follow up
Using Netbeans 6.5 as my IDE I have found that Groovy to integrates better with Java projects then Jruby. I am not sure if lack of integration is a failing of Jruby or Netbeans. But after using it for alittle Groovy definitely seems to have a leg up.

+1  A: 

I've only had experience with Jython and Groovy. The biggest disadvantage with Jython, at the moment, is that the latest release recommended for production (2.2.1) has a feature set that "roughly corresponds to that of Python-2.2" (Jython FAQ). There is a beta implementing what I assume is Python 2.5, which is now a version behind. Don't know if the same can be said for JRuby.

Anthony Cramp
Yes Jython hasn't been moving with the speed of CPython, that should hopefully improve in the future as Sun now has people working on it full time.But still Python 2.2 skills are more applicable outside of the JVM then Groovy.
James McMahon
Yep, agree. I rushed my reply this morning (trying to get out the door to work). Groovy does have some nice syntactic sugar though. I particularly like being able to cast a map of strings (representing method names) to closures (method implementations) as the implementation of an interface.
Anthony Cramp
Jython has officially release 2.5 now. Let's hope it's as good as JRuby.
jpartogi
A: 

I don't know why you should choose Groovy because I don't know your background. If you are a Java developer Groovy feels more similar to your current language then JRuby or Jython. Groovy combines the best of Java, the language, Java, the platform, and Ruby the language.

+21  A: 

I've done pretty extensive development in Ruby and Groovy (as well as a little Jython using Grinder as a load testing tool).

Of the 3, I prefer Groovy the most. I like the closure syntax the best and I think that it has the tightest integration in how it works with other java classes on the JVM. It's been a little while since I last used JRuby, but importing Java classes and working with the classloader in JRuby didn't feel as clean to me.

The fact that Groovy is also essentially a superset of Java means that the huge population of Java programmers out there will have a quicker uptake time in picking Groovy up over Ruby/JRuby. They can start programming it like it's Java and slowly start inserting idomatic groovy as they pick it up.

More to the point of what you're asking, I think that another advantage of Groovy is that the language that you go to when you want to optimize something is almost the exact same syntax, it's Java. If you're working in the Ruby or Python worlds, you're going to have to go to either C which is a big shift or Java, which is also quite different than those languages. Programming in Groovy tends to help keep your Java skills somewhat sharp as well.

If you have particular access to a Ruby or Python infrastructure, or a team that has familiarity with those kind of environments, then I could see choosing one of those other languages.

Really, all 3 of them are very nice languages and what you pick should depend more on the problem that you're trying to fix and the resources that you have available to you. Once you've become proficient in one dynamic language, picking up a second or a third is much easier.

Ted Naleid
+3  A: 

I think Dick Wall gave a very good summary of the differences between these three on the Java Posse podcast (#213, about 34:20 in) ... "JRuby was designed to make programmers happy ... it's a programming language developer's choice; Python has very strong roots in simplicity and education; Groovy is aimed squarely at being the choice for Java developers ... it's a very familiar environment for Java ... with support for annotations".

In terms of moving the language outside of the JVM, I don't think the Java runtime imposes much of an overhead -- it's a simple install, and you need to set some environment variables -- but it does provide a number of benefits including a mature runtime which has been highly optimised, and a large set of libraries. The JRuby team are now reporting better performance than the native MRI. http://blog.headius.com/2008/08/twas-brillig.html

Andrew Whitehouse
Thanks for the answer, who doesn't love the Java Posse?
James McMahon
A: 

I would say the main reason for switching to it is the funky sounding name. But afterall, I am just a troll...

mike nvck
It's not Digg...
ivan_ivanovich_ivanoff
+7  A: 

I would say if you need to mix Java with Jruby/Groovy, go with Groovy. As everybody said, Groovy has tighter Java integration.

But as far as the language implementation goes, I prefer the Ruby language over Groovy, the language is revolves around itself, in Groovy there are some hacks that are inherent to the implementation itself (just watch a Grails stacktrace vs. a Rails stacktrace and you'll see what I mean).

I highly recommend seeing Neal Ford's comparison of Groovy and JRuby

Miguel Ping
Thank you for the link. It is interesting, but I also feel like I missing a significant component by not having the speech that accompanied the slides.
James McMahon
The link is broken.
Kim
The list of past conferences: http://www.nealford.com/mypastconferences.htm takes you to a github repository of presentations: http://github.com/nealford/presentations and this is a direct link to the PDF of Groovy vs JRuby: http://github.com/nealford/presentations/raw/master/Comparing%20Groovy%20and%20JRuby%20(Neal%20Ford).pdf
i5m