This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Groovy and the fly likes Groovy in Action: A Couple of Questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Groovy in Action: A Couple of Questions" Watch "Groovy in Action: A Couple of Questions" New topic
Author

Groovy in Action: A Couple of Questions

Joshua Smith
Ranch Hand

Joined: Aug 22, 2005
Posts: 193
Welcome Dierk, Andrew, Paul, Gullaume and Jon-

I have a couple of questions for you all.

1) A number of seasoned Java programmers are seriously looking at a place in their toolbox for scripting languages running on the JVM and specifically scripting languages in the context of web frameworks. Could you explain what the advantages of Groovy and specifically Groovy on Grails are as compared with Ruby/JRuby on Rails?

2) I've heard good rumors about Ruby/JRuby support coming to NetBeans. Is there equivalent support for Groovy in NetBeans or Eclipse and/or what environment do you recommend for Groovy development?

Thanks,
Joshua Smith


Rational Pi Blog - Java, SCJP, Dev Bits- http://rationalpi.wordpress.com
Dierk König
author
Ranch Hand

Joined: Nov 01, 2006
Posts: 43
1) Groovy is specifically designed for the JVM, obeying the Java architecture and code appearance. It leverages what is available in the Java world, keeping the perspective of a Java programmer.

2) Groovy plugins are available for a number of IDEs, including NetBeans, Eclipse, IntelliJ IDEA and others.

regards
Dierk
Tug Wilson
Ranch Hand

Joined: Dec 12, 2006
Posts: 33
I'm sure a Grails person will be along soon to give you an authoritative answer to that part of your question.

If you are looking for a dynamic language optimised for the JVM than I think Groovy has the edge over the alternatives. The integration with Java is seamless. There are no special libraries to import to work with Java classes. Java code can work with Groovy classes without knowing or caring that they are written in Groovy. Java classes can subclass Groovy classes and Groovy classes cab subclass Java classes. There are some really subtle issues in selecting methods which can only really be solved if, like Groovy, you allow values to be optionally typed or to be cast to a type.

Groovy, unlike Ruby supports Unicode without the need for converters and helper packages. This makes things like XML manipulation really very simple.

I understand that the Netbeans people want to improve their support for all dynamic languages and that a very welcome attitude. There is an existing Netbeans project called Coyote which aims to do this but it's not very visible at the moment. We gave IDEA and Eclipse plug-ins for Groovy. The Eclipse plug-in in particular is very popular and is being energetically developed at the moment.

One of the Groovy books being published in the next month or so (http://www.amazon.com/o/ASIN/0123725070/) will come with a custom IDE which has been developed to support ther use of Groovy as a teaching tool - I'm looking forward to playing with that tool.
Joshua Smith
Ranch Hand

Joined: Aug 22, 2005
Posts: 193
Dierk-

Regarding number 1, could you give some examples or maybe a comparison between how you would do something in Ruby/JRuby vs. the way you would do it in Groovy and why the Groovy way is better?

Thanks,
Josh
Joshua Smith
Ranch Hand

Joined: Aug 22, 2005
Posts: 193
Tug-

Excellent information. Thanks.

Josh
Clifton Craig
Ranch Hand

Joined: May 26, 2006
Posts: 103
Joshua,

I'm no authority but I feel inclined to shoot my mouth off on this topic. Basically Dierk and John are referring to Java integration. Ruby is an entirely different language with an entirely unique API whereas Groovy is more of an extension or enhancement to the Java language. Here's a perfect example of code you can write in Groovy:

The idea here is that the barrier to entry or learning curve is much more shallow for beginners. Not being a Ruby expert I'm only guessing the Ruby equivalent would be something like:

While that looka like a counter example of Groovy's advantages consider the following Groovy equivalent:

Or even:


Groovy takes the appraoch of bringing all of the things programmers want into the Java language while Ruby is a whole new language and platform created from the ground up. There is the JRuby project that allows you to run Ruby scripts on a JVM but again the API is recreated. From what I've seen so far Groovy can do just about everything Ruby can do but with tighter Java integration. That's not to say that Groovy is better than Ruby but that it may be easier to adopt for the typical Java programmer. I provide a more in depth explanation of the above rambling here on my site.


Holla at me...<br /><a href="http://codeforfun.wordpress.com" target="_blank" rel="nofollow">http://codeforfun.wordpress.com</a>
Joshua Smith
Ranch Hand

Joined: Aug 22, 2005
Posts: 193
Clifton-

Thanks for the examples. That's exactly the kind of information that I was looking for.

Josh
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
Hi -

Originally posted by Clifton Craig:
... guessing the Ruby equivalent would be something like:


I have reached the stage that whenever I see + signs between strings, I think: "They are thinking in Java, not Ruby."

One step forward is:



And then once you realize that the stuff inside the #{...} placeholder can be more than just variables:



Regards, Guy
Clifton Craig
Ranch Hand

Joined: May 26, 2006
Posts: 103
Good point Guy,

I was thinking in Java. As you pointed out Ruby allows string interpolation making the hello world example more trivial. The Groovy equivalent would be nearly identical replacing #{} with ${}
 
Consider Paul's rocket mass heater.
 
subject: Groovy in Action: A Couple of Questions
 
Similar Threads
Unsure if this is worthwhile
Look for a excellent script!!!
Ruby
Groovy, a new scripting language, yeeeha, so what ?
JRuby benefits?