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


   

 
 
Download Current Issue
ISSUE 3/15/2010 PDF

Need Back Issues?
DOWNLOAD HERE

Receive the print Edition?


 
blogs tab
ASP.NET MVC 2 Ships
ASP.NET MVC 2 has shipped.
03/12/2010 10:26 AM EST

Microsoft plans 'open' Silverlight analytics framework
Microsoft is going to announce a multipurpose analytics framework for Silverlight at MIX.
03/11/2010 09:51 AM EST

About CSS processing
Two sites that lead to a startling CSS conclusion.
03/10/2010 02:29 AM EST

 

Events calendar tab
3/14/2010 to 3/18/2010
Seattle, Wa.
SHARE

3/15/2010 to 3/18/2010
Santa Clara, Calif.
TechWeb

3/15/2010 to 3/17/2010
Las Vegas
Microsoft

3/16/2010 to 3/19/2010
Las Vegas
Penton Media

3/17/2010 to 3/19/2010
Las Vegas
TechTarget


 
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