News on Monday
more>>
SharePoint Tech Report
more>>


   

 
 
Download Current Issue
ISSUE 2/1/2010 PDF

Need Back Issues?
DOWNLOAD HERE

Receive the print Edition?


 
blogs tab
Is Microsoft eyeing Office subscription pricing?
Microsoft may be preparing to offer a new Office pricing option called "union," which charges the same for cloud as on-premises.
02/01/2010 09:38 AM EST

Facebook rewrites PHP runtime
Facebook is about to open source its own PHP runtime, written from scratch for speed.
01/30/2010 08:53 PM EST

There WILL be a JavaOne this year
JavaOne will happen in 2010, as a co-located event with Oracle's OpenWorld, on Sept. 19-23 in San Francisco.
01/27/2010 01:02 PM EST

 

Events calendar tab
2/9/2010 to 2/13/2010
San Francisco
IDG World Expo

2/10/2010 to 2/12/2010
San Francisco
BZ Media

2/17/2010 to 2/25/2010
Atlanta
Python Software Foundation

2/19/2010 to 2/20/2010
Los Angeles
SCALE

2/21/2010 to 2/24/2010
Las Vegas
IBM


 
Most Read Latest News Blog Resources

Feeling Groovy at Last




February 1, 2007 — 
After many delays, the Java scripting language Groovy is finally shipping. The 1.0 release became official the first working day of this year, and it promises to bring lots of good things to many a Java developer.

Groovy is a dynamic scripting language that was purpose-built for the Java platform. By this I mean that it is not the port of another idiom (in the Jython, JRuby mold), but a language that was designed for the JVM and specifically for use by Java developers. The goal—which appears to have been met—was to provide a simplified syntax for much of Java’s notoriously wordy code.

Groovy does away with the tediousness via lots of syntactic sugar that makes Java development really a pleasure. For example, when you define a class, Groovy automatically creates default getters and setters for fields. Lists and maps—Java’s most overused collections—are first-class members of the language. You declare and load them with values in a single concise statement akin to Java’s syntax for arrays.

Groovy also offers closures, which are a technique made famous by Ruby. Closures have many definitions, and a rather dull meme in programming language blogs these days is arguing over what constitutes a closure. Putting aside the academics’ sparring, closures are essentially anonymous blocks of code that are easily attached to a statement or function. They make it simple to specify an action without having to define a class and then a method. Instead, the actual code to be executed is stated inside parentheses and attached to another action. For example, a closure called find, let’s say, can be attached to a collection iterator to look for a specific element. The closure contains only the equality statement to test for the desired element. Another one, called each, can be attached to indicate actions that should occur for every element in the collection. This design makes for concise code that is readily understandable.

Groovy offers lots of other convenience features in areas where Java and other traditional languages tend to be weak, such as duck typing and special syntax to simplify common tasks like XML processing.

Last year, I discussed my frustrating search for a good scripting language for Java. I ended up using NetRexx, which is an easy-to-learn and elegant language. However, it has not been updated in a long time and has nearly no community around it. These things matter, especially once you get into serious coding. Groovy has all these items in place.

For starters, it has an active community that responds quickly to queries and doesn’t make newbies feel like they are unwashed ignoramuses. This community has given Groovy many of the accoutrements needed by a robust language: plug-ins for most IDEs, including Eclipse, JetBrains IntelliJ IDEA and NetBeans; JUnit support (in fact, some developers use Groovy especially for the ease of writing JUnit tests on regular Java code); and a plug-in for Ant (called Gant).

Moreover, Groovy integrates completely with Java. You can call Java classes and access Java objects natively. In the other direction, you can embed Groovy into Java apps easily. As a dynamic language, Groovy can be run from the command line either as an interpreter or through the usual compile process. The software and the basic docs are available as open source from groovy.codehaus.org. The definitive book on the language is Manning Press’ excellent “Groovy in Action,” which was written by several project leads.

The language’s long incubation has enabled Groovy-based projects to develop right along with it. One of these is Grails (formerly called Groovy on Rails), which provides a framework like Ruby on Rails for Java developers. It transparently uses Hibernate and has support for AJAX front ends, in addition to all the ease-of-use features of the Rails design. (A book on Grails development, “The Definitive Guide to Grails,” has just been released by Apress.)

There are many dynamic languages that run on the JVM. Groovy is unique in that it combines several features: It is purpose-designed for Java developers; it is supported by a JSR (JSR 241); it is supported by several vendors such that the chief technical lead works full-time on the language; and it has a robust tool set and an active community. For these reasons, I think Groovy has legs and could well emerge as the primary scripting language for the JVM.

I hope some of its features will rub off on the Java language itself, as Sun continues to find ways to make Java programming easier. In the meantime, have a look at Groovy and tell me if you don’t agree.

Andrew Binstock is the principal analyst at Pacific Data Works. Read his blog at binstock.blogspot.com.


Share this link: http://www.sdtimes.com/link/30044
 

Add comment


Name*
Email*  
Country     


  • Comment
  • Preview
Loading