Scott Hickey

Greenhorn
+ Follow
since Dec 12, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Scott Hickey

Originally posted by Gregg Bolinger:
I could use my exising JDBC libraries, write tests and run JUnit, compiled the Groovy source into .class files and jar them up.

My question to this is, then why use Groovy? If you are going to compile to bytecode anyway, and jar them up, why not just stick with Java. When I think of using a scripting language, I think of it as an on-the-fly type of use. For example, I have an application written in Java. I would like users of my application to be able to extend it without having to recompile my code. Pretty much a plugin architecture, but with zero compiling. If that makes sense at all.

Aside from that, I'd assume a scripting language like Groovy to make a few things simpler with a simpler syntax. But again, my biggest problem is finding the niche for any scripting language.



How to use Grovy really depends on your application. For a large, real world Java J2EE app, the readability of the simpler syntax was huge in two important areas - collections and decimal math. Imagine a sales system where there may be more than one proposal, where each proposal consists of products that have configurable features. To calculate the costs, using BigDecimal, Groovy code literally looks like the following.

This is something that I can (and do) review with a business subject matter expert and it is relatively painless. With Java, you have to use the BigDecimal method calls such as add() and multiply() which make the code unreadable for anything non-trivial, even for expert Java programmers. Trying coding something like ((a * b) - (c * d)) / e in using Java BigDecimal and you find one Groovy's sweetspots. Notice in the code above, there setters and getters are implied in all of the calls and there are no type declarations, exeception handling or type casting this code.
[ December 13, 2006: Message edited by: Jim Yingst ]
17 years ago
Since we're on *Java* Ranch and assuming you want to integrate Groovy into a Java application or deploy in Java shop, for me Groovy really stood apart from the other language is several respects. It was really designed for the Java environment from the ground up in the sense that 1) syntactically it is was much easier to start coding in and 2) it integrates into Java in ways that I was already familiar with.

For my project, I got started quickly using a simple editor and Ant. I could use my exising JDBC libraries, write tests and run JUnit, compiled the Groovy source into .class files and jar them up. For me coming from the Java world and knowing I was going to have to integrate with other Java components, the barrier for entry was really, really low.
17 years ago
Swing + Groovy is covered in chapter 8 of Groovy in Action.
17 years ago
Speaking from my experience of using Groovy as part of a large Java J2EE project, there were several factors that made Groovy stand out.

The component being targeted by a language other than Java involved alot of complicated math and data set manipulation. Like Ruby, Groovy has really nice language support for manipulating collections of object. Unlike many of the other languages including Ruby,Python and Rexx, Groovy naturally understands Java classes and can be precompiled into Java byte code so deployment is a piece of cake. To the corporate infrastructure folks, it's just another Java jar.

One area that Groovy stood out from ALL of the other languages we looked at (besides Rexx) was the native BigDecimal support. Since accuracy is important in any business application that deals with money, this was a big plus. Using a float or double would not be appropriate for any of the decimal attributes we use. All of the other languages we looked required explicit calls to create BigDecimal objects.

Groovy has many other great features but these were the ones that were significant given the business domain and the need to integrate into a Java environment.
17 years ago
On a project I work on, we use Groovy for a calculation component. We compile the Groovy using Ant and package up the class files in a jar. The jar is wrapped in an EJB. When compiled into .class files, Groovy integrates with Java seemlessly.
17 years ago