Groovy advantages over Jython or Jruby?
Asked Answered
W

5

34

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.

Waksman answered 13/11, 2008 at 20:2 Comment(6)
This isn't worth posting an answer for, but like most languages Jython / JRuby / Groovy are domain-agnostic-- they will all do what you want more or less. Just pick the one you are best at :-)Obtect
Or alternatively, the one with the coolest name.Obtect
So you are saying there is no advantage to using groovy over the other two?Waksman
I'm saying there is no inherent advantage to coding in any of the three. People spend too much time deciding what language or framework to use instead of just Getting It Done.Obtect
Perfect question. Exactly what I was wondering.Gentle
Perf benchmark, 2013 results: JRuby 4x> Groovy 2x> Jython.Slaughter
A
38

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.

Alic answered 14/11, 2008 at 4:45 Comment(0)
T
14

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 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

Tropous answered 17/11, 2008 at 12:34 Comment(2)
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.Waksman
The list of past conferences: nealford.com/mypastconferences.htm takes you to a github repository of presentations: github.com/nealford/presentations and this is a direct link to the PDF of Groovy vs JRuby: github.com/nealford/presentations/raw/master/…Hag
I
3

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

Insurgent answered 14/11, 2008 at 14:35 Comment(0)
F
1

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.

Fireboat answered 13/11, 2008 at 20:27 Comment(3)
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.Waksman
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.Fireboat
Jython has officially release 2.5 now. Let's hope it's as good as JRuby.Choline
P
1

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.

Pollaiuolo answered 13/11, 2008 at 21:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.