wood burning stoves 2.0*
The moose likes Groovy and the fly likes Why will I use Groovy? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Why will I use Groovy?" Watch "Why will I use Groovy?" New topic
Author

Why will I use Groovy?

Daniel Jabonete
Ranch Hand

Joined: Apr 01, 2007
Posts: 76
...?
Marko Kencheto
Ranch Hand

Joined: Jan 15, 2008
Posts: 33
Interesting whether these articles corresponds the real truth?!!
http://en.wikipedia.org/wiki/Groovy_(programming_language)
http://www-128.ibm.com/developerworks/java/library/j-alj08034.html
Daniel Jabonete
Ranch Hand

Joined: Apr 01, 2007
Posts: 76
Thanks Serg for the informative links!

So Groovy is another OOP Language, why will I use it, as a Certified Java Professional point of view. Does it offer other features I cannot do with Java?
Venkat Subramaniam
Author
Ranch Hand

Joined: Jan 28, 2008
Posts: 79
Groovy is lightweight, dynamic, and provides a higher level of abstraction, but at the same time, you can mix it with Java. If you are interested in Aspects, you can do that with Groovy very easily using MOP or MetaObject Protocol. Groovy enhances Java instead of replacing it.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi guys,

I hope I may join this discussion because for me it's the same question: "Why Groovy (or other dynamic and scripting languages)?

I've been searching quite long for real advantages of languages like Groovy but I still haven't found them. At least I can't imagine to use such a language for programming serious applications. Don't get me wrong, I would like to see some benefits in using Groovy where appropriate and perhaps better than Java. But a lot of the "features" of dynamic languages appear to me as disadvantages. For example all the useful compile time checks and IDE support (auto completion etc.) are missing or not really good.
But most important for me is the big difference when you have to look at some piece of source code. Code in Groovy (and other similar languages) often may be much shorter or concise than the same code in a language like Java. But if it's not my own code and it's more than just a few lines, it's exactly this advantage which becomes a big disadvantage in my opinion. You can't figure out what types some variables might have, a lot of this useful "magic" going on isn't really easy to understand and so on...

So I see Groovy's place where you have to script a fast and small solution to a specific problem. Or if someone is new to programming and quickly wants to see results it could be nice. And it may come in handy when you don't have a powerful IDE to work with. Of course this is only my personal opinion. Perhaps someone finally can convince me when and why I should give Groovy a try. Or can "Programming Groovy" perhaps show me what advantages of Groovy I'm missing as a "normal" Java programmer?

I'd be glad to hear your opinions to that!

Marco
john Lin
Greenhorn

Joined: Dec 03, 2002
Posts: 8
I have to agreed with Marco. I started to learn this new language Last month and am still have wandering about the "if and when I can use it in my development"

It would be nice if some one can share some good experience about using this in decent size of development project.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

But a lot of the "features" of dynamic languages appear to me as disadvantages. For example all the useful compile time checks and IDE support (auto completion etc.) are missing or not really good.

They're getting better, especially compiler checks. IntelliJ IDEA has done a terrific job leading the way. Autocomplete is fairly decent. As you learn to program more Groovily, though, you'll discover that you don't need to use autocomplete nearly as much simply because you write less code.

But most important for me is the big difference when you have to look at some piece of source code. Code in Groovy (and other similar languages) often may be much shorter or concise than the same code in a language like Java. But if it's not my own code and it's more than just a few lines, it's exactly this advantage which becomes a big disadvantage in my opinion. You can't figure out what types some variables might have, a lot of this useful "magic" going on isn't really easy to understand and so on...

Java is a butter knife. Groovy is a chef's blade. If you let a fresher in the kitchen, yes it's more dangerous to give him/her a sharper tool. From my perspective, the only advantage Java has here is when you're dealing with an inexperienced programmer because then the programmer will simply make less of a hack-job.

In some places our "chef" might realize that a portion of code is cleaner if static typing is used. You're allowed to do that in Groovy. You can go to normal Java ways when you need to.

I believe that people who write horrible Groovy code will also write horrible Java code. If some goofball starts passing around an indecriptive variable called flag (or worse, f), in Java I'm guaranteed that I'll know its type is boolean. This gives me a lowest common denominator for bad code in Java, somewhat like a safety net.

Follow a few simple principles like keeping methods succinct, and code will be easier to read.

Perhaps someone finally can convince me when and why I should give Groovy a try. Or can "Programming Groovy" perhaps show me what advantages of Groovy I'm missing as a "normal" Java programmer?

Why do you feel someone needs to convince you? If you're happy with Java as it is, then stick to it. But if you're hungry for a more powerful tool, Groovy's one of the best and most fun to explore.


A good workman is known by his tools.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Originally posted by john Lin:
It would be nice if some one can share some good experience about using this in decent size of development project.

I'm currently using it in an SOA architecture that has an MQ backbone.

Groovy has made it tremendously easier to deal with XML messages in our services by using cool things like XmlSlurper and MarkupBuilder.
Tina Ma
Ranch Hand

Joined: Nov 29, 2007
Posts: 198
How good is unit testing with our old JUnit for .groovy classes?


Tina
SCJP 1.4, SCWCD 1.4
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Thanks a lot for your detailed answer, Marc!

Java is a butter knife. Groovy is a chef's blade. If you let a fresher in the kitchen, yes it's more dangerous to give him/her a sharper tool. From my perspective, the only advantage Java has here is when you're dealing with an inexperienced programmer because then the programmer will simply make less of a hack-job.


What a cool metaphor But that was indeed another problem I suspected to have when you use Groovy for bigger projects. On the other hand you're of course right. With most programming language it's possible for good programmers to produce good code and on the other hand for bad programmers to produce bad code. Perhaps I'll have to gain some experiences in practical use of Groovy. At the moment I'm still not convinced if it's better to leave it to programmers to produce better or cleaner code (or bad code as well).

Why do you feel someone needs to convince you? If you're happy with Java as it is, then stick to it. But if you're hungry for a more powerful tool, Groovy's one of the best and most fun to explore.


That's mostly because I don't belong to that kind of people who only like what they already know and don't even try to learn something new. And of course it's alway interesting to learn new technologies in particular if they could make daily work easier.

So you have convinced me in some points already. And I guess there's a lot of learning by doing like in many other areas of computer science. Which way would you recommend to get started with Groovy? Using it for daily scripting? Trying to integrate it in some parts of real application programming?

Thanks in advance for all the tips!

Marco
Chris Patti
Greenhorn

Joined: Apr 08, 2008
Posts: 7
Originally posted by sreerupa basu:
How good is unit testing with our old JUnit for .groovy classes?


Very good. I'm just a build monkey (release engineer) but we have a very large application here at The Broad Institute, and more and more developers are utilizing Groovy for their unit tests. Less boiler plate code and more abstraction means two things: It's much easier to construct meaningful, correct tests, which makes developers more likely to write said tests, and everyone's quality of life improves.

One test in particular went from hundreds of lines to less than 10, and readability actually improved! Groovy for testing is a win, pretty much hands down.
Daniel Jabonete
Ranch Hand

Joined: Apr 01, 2007
Posts: 76
I believed most of us here are in search (or hungry) of much powerful and at the same time fun to explore tools. But before integrating or introducing these tools in particular projects some justifications are needed, especially with the management. Some organization preferred or implemented a certain standard approaches. If it is just an enhancement it can be maybe consider later, if it is �mix� then that seems a red light.

But ofcourse for our own personal time, we can try anything we want.




x----------x

In the Art of War:

�Divide and Conquer�
[ April 08, 2008: Message edited by: Daniel Jabonete ]
Ravikiran Vishnuvajhala
Ranch Hand

Joined: Jan 11, 2006
Posts: 30
I have also found this interesting article on the advantages of using Groovy for JUnits -

http://www.javalobby.org/java/forums/t94245.html
Marko Kencheto
Ranch Hand

Joined: Jan 15, 2008
Posts: 33
Interesting: ability to learn new technologies is allways very important, but what do you do in case, if the head allready look like filled tee cup till edges??? Is everything limited or not?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Well, most of us just go on and learn new stuff and gradually forget the old stuff we haven't used in a while. This generally happens naturally. Does your memory throw an InsufficientMemoryError instead?
[ April 11, 2008: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

How to get started?
Fool around using the Groovy Console. This tool makes it pretty easy to quickly try new concepts in Groovy without an IDE. I had a lot of fun finding SwingBuilder examples online and dropping them into the Groovy Console. Voila! Instant Swing app!

How to introduce Groovy in a project?
In some companies this may be an uphill battle. One of the easiest ways to start using Groovy is if you work on a project that's not doing as much unit testing as you'd prefer. You can easily set up Groovy unit tests and even choose not to commit your Groovy code to the repository if you think management would throw a fit. You find more errors in the code base and you get experience with Groovy - sounds like a win-win to me.
Josh Brown
Ranch Hand

Joined: Oct 09, 2007
Posts: 35
Marc makes a great point - unit testing is an easy way to sneak some Groovy into your project.

I've been really interested in Groovy and am currently on a project that doesn't use it. I'm maintaining an older application, and the app didn't have any unit tests at all when I started. I decided to write some units test using Groovy, and it's great! Groovy just looks so much nicer than Java, and it provides a lot of nice features that are great for unit tests.
[ April 11, 2008: Message edited by: Josh Brown ]

Josh
Inside the Machine
Marko Kencheto
Ranch Hand

Joined: Jan 15, 2008
Posts: 33
Hi Jim,

thanks, i'm not "Terminator", but sometimes mark, that happy peoples are that one, that find "middle" beetween experience (application of learned stuff in reality) and lerning proccess... my oppinion -it can be wrong!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why will I use Groovy?