wood burning stoves
The moose likes Groovy and the fly likes Groovy Versus Java for the authors of Groovy in Action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Groovy Versus Java for the authors of Groovy in Action" Watch "Groovy Versus Java for the authors of Groovy in Action" New topic

Groovy Versus Java for the authors of Groovy in Action

Jonathan MBaker

Joined: Jul 08, 2003
Posts: 7
We have a new developer on our team who just graduated from college. She is just beginning to learn the ins and outs of java. I suggested that as she is working her way through tutorials that she also be learning groovy. After a day or so of this, she came to me very excited, and wanted to know why she should continue to learn java when a language such as Groovy existed.

I explained about the higher overhead when using groovy as the class files generated are bigger than the corresponding java class files, but I wasn't really secure in my answer. Obviously, since there are many products at our company written in java, she will need to learn java to help maintain existing apps, and such. With the continued rise of ruby and rails, I think that maybe there is no driving reason that she couldn't learn groovy as her primary language.

Do you think you could explain the main advantages and disadvantages of using groovy over core java.
Tug Wilson
Ranch Hand

Joined: Dec 12, 2006
Posts: 33
It's very good to hear that you have managed to hire such an intellegent and talented developer

In most cases we don't consider Groovy as an alternative to Java. We look at it as an ajunct to Java.

Many Groovy users develop the whole of their application in Groovy. They find the development time considerably shorter than in Java and the source code is lots more compact and lots less "noisy' so it is easier to understand what the code is doing.

Often performance will be satisfactory at that point. Especially if the application is making use of substantial Java libraries so that most of the processing time is spent in Java generated bytecodes.

If there is a performance issue then it's pretty easy to profile the app and find the hotspots. It is then really easy to move the this code into Java. For example if you have a method on a Groovy object which is taking a log time to execute just subclass the Groovy class with a Java class and override the method with a Java implementation.

Just over a year ago I was consulting with an early Groovy adopter who has a 40,000 line Groovy application which is key to a part of their business. They had a performance problem and were not able to meet their response targets. I was able to use Groovy's dynamic capabilities to instrument the application without changing any of their code. We found that the problem was that BigDecimal division was taking a very long time (it's a financial application). Recoding two methods in Java (less than 50 lines of code) fixed the problem. They have gone on to extend the application and are very active members of the Groovy community.

We have had on Groovy user who implemented a signal processing application in Groovy. The performance was not acceptable, of course. However he claimed that his development time was a fraction of what it would have been in Java and developing it in Groovy and then re-coding in Java was far quicker than developing in Java.

Groovy is not a silver bullet, of course. However we are finding that programmers really like the dynamic nature of the language and love the ability to dip in and out of Java. Of couse, the availability of the vast set of Java libraries is a real benefit too.
Martin Martin

Joined: Dec 12, 2006
Posts: 1
In the future (perhaps not relevant to your new hire), I see most programs being written in dynamic languages, with the core parts being rewritten in a statically typed language. For 4 decades or so, studies have shown that programmer productivity is roughly constant in lines of code, from assembly through Fortran to perl/Tcl/Python. So you should be able to get things done much faster in Groovy than Java. Because of Groovy's tight integration with Java, multi-language development is greatly eased. For example, if you were to program in Python, coding the inner loop in C++, you have to write a lot of "glue" code because a Python class is very different from a C++ class. But a Groovy class *is* a Java class, you don't need any wrappers to call existing Java classes.

So, in the future, I really see dynamic languages and multi-language development taking off. And because of Groovy's tight integration with Java, I see it as a natural for that space.
I agree. Here's the link: http://aspose.com/file-tools
subject: Groovy Versus Java for the authors of Groovy in Action
jQuery in Action, 3rd edition