Thursday, December 26, 2013

I am looking on a new language to pick up and found out about Groovy. According to the website, the language is 'agile dynamic' language.
  1. How is it Agile?
  2. How shorter are the syntax compared to Java's?
  3. Can I use existing Java libs out there?
  4. Lastly, can anyone share their experience on this lingo? What you love and hate
shareimprove this question
 
This question would really be better suited to Stack Overflow –  Crippledsmurf Jan 27 '11 at 4:38
1 
My understanding is that Groovy is essentially Java with less template syntax and duck typing (strong typing, but determined at runtime instead of compile time). It's been a looong time since I looked at it, so I don't know if they added any other features. Documentation is where I get hung up. –  Berin Loritsch Jan 27 '11 at 13:48
add comment

migrated from superuser.com Jan 27 '11 at 6:51

This question came from our site for computer enthusiasts and power users.

4 Answers

  1. I don't know either exactly what makes a language "agile", but Groovy let's you put something together quickly.
  2. Depending on your style, quite a lot. You can leave out a lot of Java's boilerplate code, there are no checked exceptions etc.
  3. Yes, without problems.
  4. Mostly I love it, because I like to get things done quickly; I also like that it feels a lot like JavaScript (e.g. Groovy's closures and Javascript's anonymous functions are relatively similar), which is a good thing in a project that uses both; on the other side, many typos are not found by the IDE or the compiler, but only during runtime. Likewise, Intellisense support in the IDE (Netbeans in my case) is by far not as good as in Java. For that reason, I find myself googling the API more often than I would in Java.
shareimprove this answer
add comment
  1. A language can not be agile anymore than a car can be liberal . . . though certain cars may appeal to liberals . . .
  2. The syntax is shorter and more concise in several ways.
    List<String> myList = new ArrayList<String>();
    myList.add("one");
    myList.add("two");
    myList.add("three");
can be shortened to
    def myList = ["one", "two", "three"]
Another way that you write less code is that you needn't catch or explicitly throw any exceptions. Obviously, it's up to you to make sure that your application recovers gracefully from errors, but this is really nice when you are writing a script that does some file I/O.
One of the most important resources to understand how your code can be shorter is the Groovy JDKwhich lists the methods that Groovy adds to your familiar Java objects.
3.Yes, this is the biggest advantage of Groovy over Python or Ruby.
4.I've enjoyed it a lot, particularly in connection with Grails. But if I find myself working on a Java team, I expect to use Groovy for scripts, and for test code, when possible. The biggest disadvantage is the tool support, Eclipse and NetBeans are not ready for prime-time with Groovy. IntelliJ makes it tolerable. Ultimately, Groovy successfully removed most of the boring and awkward parts of Java.
Some good resources: Groovy Goodness Practically Groovy
shareimprove this answer
 
Your List example is not fair to Java, since List myList = new ArrayList(); works just as well, and is closer to its Groovy counterpart. –  user281377 Jan 27 '11 at 12:24
 
Hoping my edit makes the advantage clearer. –  Eric Wilson Jan 27 '11 at 13:41
 
So is List myList = new ArrayList(new String[] {"one", "two", "three"}); But yes, there is a bit less template code. Oh, and regarding point 3, you can use Java libs when you are working with JRuby. The code won't be portable to C based ruby install, though. Same with IronRuby and .NET code. I don't know if there is a JRuby equivalent for Python, but for .NET there is IronPython as well. –  Berin Loritsch Jan 27 '11 at 13:46 
 
Maybe I should have gone with def map = [one:1, two:2, three:3]? –  Eric Wilson Jan 27 '11 at 13:49
 
There is no equivalent for that in one line in Java for sure. But the practical differences really aren't so dramatic.–  Berin Loritsch Jan 27 '11 at 13:52
show 2 more comments

No comments: