• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Groovy in Action: A Couple of Questions

 
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tug-

Excellent information. Thanks.

Josh
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Joshua Smith
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Clifton-

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

Josh
 
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ${}
 
reply
    Bookmark Topic Watch Topic
  • New Topic