• 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

Advantages of Groovy over other scripting languages ?

 
Ranch Hand
Posts: 572
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm curious about Groovy . It is described as a scripting language .
I understand that it compiles to Java code
Does this mean that you have to install a Groovy specific engine other than the JVM on your server like PHP does ?

What advantages are there to using Groovy over something like PHP, other than a familiarity with Java ?

Thanks,
Paul
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to install Groovy which generally means downloading a zip file, unzipping it somewhere and pointing your PATH to it's bin folder. You can execute groovy scripts directly from the command line using the 'groovy' executable. Or you can compile groovy into byte code and use it just like java code.

Groovy is nice because you can take advanatage of all the existing Java resources you already use every day. You just get to write less code to get your work done. I can't say that it has any advantages over PHP, or any other scripting language for that matter, because you should always use the right tool for the job. I'm sure in some situations PHP makes more sense. Of course, as a java developer, I'd be hard pressed to find that situation. ;)
 
paul nisset
Ranch Hand
Posts: 572
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your input Gregg.
 
Ranch Hand
Posts: 686
Netbeans IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would beg to differ...Groovy works only in cases where your requirement is aligned with convention like CRUD. Anything more than that, you need to work on technology more than business matters - I guess it is waste of time.
 
author
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm not that keen on the "scripting language" label. Yes, you can use it to write scripts, but that's not really its strength. Also, Groovy currently has a delay on starting up (similar to the one Java used to have in the old days), so it's not that great for writing scripts that you run from the command line.

I prefer the label "dynamic language" since it's more accurate. So you get full dynamic typing and you can change the behaviour of classes at runtime (for example by adding a method). The biggest advantage over both PHP and Ruby is that Groovy integrates so well with Java. You can even have a Java class refer to a Groovy class which refers to other Java classes. It also has the benefit of having very similar syntax to Java. If you have a Java infrastructure, then Groovy is usually the best option for dynamic languages. Before I get flamed, there is JRuby too, but I'm not sure what the status of its Java integration is.

One final thing: if you want to use Groovy as a scripting language, then you typically have to install Groovy locally. However, if you simply want to use it from a Java or Grails project, then the relevant JAR file is all you need (Grails already includes it).

Cheers,

Peter
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vyas Sanzgiri wrote:I would beg to differ...Groovy works only in cases where your requirement is aligned with convention like CRUD. Anything more than that, you need to work on technology more than business matters - I guess it is waste of time.



I think you are talking about Grails here, which is more than Groovy. In any case, you're making false assumptions.
 
paul nisset
Ranch Hand
Posts: 572
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I appreciate everyone's input.
I found Peter's comment that it can link into Java apps via a jar file particularly useful .

I'm mainly curious about how it's used in a web application as opposed to a stand alone app
that you would run like "java myapp_with_main_method " .

Thanks,
Paul
 
Peter Ledbrook
author
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I'm mainly curious about how it's used in a web application as opposed to a stand alone app
that you would run like "java myapp_with_main_method " .



You can use Groovy for anything that you might use Java for. It's XML processing is particularly strong. As an example, check out GroovyServlet:

http://groovy.codehaus.org/api/groovy/servlet/GroovyServlet.html

You just have to make sure that you use the Groovy compiler to compile the Groovy files. There is an Ant task you can use, or there is the GMaven plugin for Maven.

Hope that helps,

Peter
 
reply
    Bookmark Topic Watch Topic
  • New Topic