My Secret Life as a Spaghetti Coder
home | about | contact | privacy statement
The first talk I attended at NFJS was Scott Davis's presentation about Groovy, and how it lives up to its name (you know, its grrrooovy baby!) The presentation went through the death of Java, how Groovy fills a need that Java misses, some sample code for utility programs, and finally a short introduction to Grails. Download Groovy As a disclaimer, I give Scott Davis all the credit for the good stuff here. I'm just reporting from my notes, his slides, and my memory, so any mistakes you find are probably mine. If they aren't, they probably should have been.

Scott first introduces us to the death of Java, or more precisely, that rumors "of [its] death have been greatly exaggerated." Instead, Java is the COBOL of the 21st century. Although it is over 10 years old now, it was designed with C and C++ in mind so you might consider it even older than that.

Scott notes that after ten years many technologies are dead (or rotten and decaying!). Does anyone still use DOS, Lotus 1-2-3, or WordPerfect? (Do you still want to?) I might be partial to DOS because that's where I cut my teeth (and the thought of using it still has me licking my chops), but other than that, I think the answer is a loud "hell, no!"

On the other hand, some technologies "age like a fine wine." Scott includes HTTP and TCP/IP in this category.

Finally, the third class of applications adapt and evolve to stay alive. FTP moved to SFTP and now we're using BitTorrent. Telnet moved to SSH and POP to IMAP. It is in this vein that Java finds itself, struggling to adapt.

It's not that Java (the language) isn't capable - it's that it gets in your way. Scott points out that in essence, the main complaint about Java is "that it is one level of abstraction too low." The soup du jour is simplicity - we want things to be "better, faster, [and] lighter." In fact, anyone who has written a line of code in Java knows he's got around 29 more to write before he's done anything useful. Scott then shows a 35 line example of reading a file and printing it out line by line to illustrate his point.

In Java, we often "develop 'util' classes to overcome this abstraction layer mismatch," Scott says, noting that being forced into having com.mycompany.StringUtil due to Sun's declaration of String as final is a code smell. Surely there is a better way!

Enter Groovy, the "first scripting language to be officially sanctioned by Sun to run on the JVM." It can run in compiled or interpreted mode and it is easy to install (though it took me some time because of less than helpful error messages about me pointing to the bin directory under Java, rather than the base Java directory). Most importantly, it fills the void of that "abstraction layer mismatch." Reading and writing lines in a file with Groovy is reduced to:

new File("simpleFile.txt").each { line -> println(line) }

Look familiar? It's definitely Ruby-esque, but based on my cursory inspection, also keeps some Java idioms where appropriate (for example, import over require). I can definitely see how it would be easy for a Ruby developer to pick up, but on the other hand, I think it would be easier for a Java developer to transition to this than to Ruby. I'm looking forward to playing with it some more.

Finally, Scott goes through some "Groovy hacks" related to File I/O, XML and HTML, SQL, Groovlets (surprisingly, Groovy's servlets), and Grails. In particular, you should have a look at the Groovy Markup way of writing markup, because its quite a bit more elegant than ><ML (that my 13375p34|< for an X). I won't go into detail about the code samples, as you can find those elsewhere (.PDF) if you wanted (perhaps in GINA, the canonical Groovy book), but I do plan to cover an introduction to Grails in a future post related to another presentation from NFJS. When I start playing more with Groovy I'll put up some real code samples then.

Thoughts about Groovy?

Hey! Why don't you make your life easier and subscribe to the full post or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!

Leave a comment

I like Groovy a lot. It's easy to get in the door at Java shops and is able to leverage the incredible amount of open source Java libraries already available. The community is exciting to be around and the Java plug-in kicks all kinds of booty. Fun stuff all around.

Posted by Blaine Buxton on Jul 07, 2007 at 07:08 PM UTC - 5 hrs

Hi Blaine -
In his keynote speech (and in the dynamic languages birds of a feather session) Scott Davis mentioned the same benefits. He couldn't stress enough that it was easier to get into Java shops than Ruby (for instance), and he mentioned the forward and backward abilities for integration with each other more than once.

He also said he doesn't specifically tell them it will be "Groovy" but goes with JSR 241 or some other vague reference to it (perhaps Java Scripting Language or something of the sort)... my memory is failing me! =)

Mention of starting to use it for unit tests was also made as a good way to introduce it to your favorite place of employment, though I don't remember if that was by Scott or someone else.

Any tips you'd like to share?

Posted by Sam on Jul 07, 2007 at 08:01 PM UTC - 5 hrs

I always liked the idea of Groovy, but now that JRuby has gone 1.0 I'm having a hard time figuring out why I'd put time into the Java specific Groovy when I could use the same time learning Ruby. I also think the huge brain trust supporting Ruby means that over time there are going to be more cool tools and concepts coming out of the Ruby world purely because it is where most of the cool kids are hanging out.

I know the idea was to sell Groovy as "scripting for Java developers" and the syntax may be a little more familiar than Ruby's for Java developers, but I'm not convinced that is going to be enough to make it a major language when Ruby has so much momentum (and people like ThoughtWorks pushing it for enterprise implementations).

Fun to play around with, but I'm not convinced it'll get the traction to make it a "must know" language like Java, C# and (I believe) Ruby. Will be interesting to see how this plays out though . . .

Posted by Peter Bell on Jul 08, 2007 at 10:59 AM UTC - 5 hrs

@Peter - Scott actually made a pretty convincing case for Groovy, and there are quite a few "alpha geeks" behind it, pushing it to Java developers (the NFJS crew being the primary vehicle, from what it appears).

I asked him via email (didn't get the chance at the conference in person after I had thought of the question) if he thought JRuby would bring all the benefits of Groovy to the JVM. I haven't yet received a reply, and I'm hoping its not because he got a "message could not be delivered" that some people get when they email me.

That said, it certainly doesn't have the traction Ruby has.

In any case, I think if you learn Ruby or Groovy you can easily switch between the two, so one ought to be good enough to say you know the other.

On another note, I don't know how easily Ruby integrates with POJOs or the other way around, but Groovy appears to do it well. In that vein, you have all the existing Java libraries at your disposal, which is definitely a huge benefit if JRuby doesn't play as well with them.

Posted by Sam on Jul 08, 2007 at 12:24 PM UTC - 5 hrs

@Peter, JRuby is a great project and Ruby a good language you should certainly learn (try to learn one a year, as the prag-programmers suggest), but in terms of Java integration, Groovy goes further and lets you use things like Java 5 annotations or even generics, something which is not possible with JRuby. With Groovy, you can use all those Enterprise frameworks like EJB 3 / JPA, Google Guice, Spring, Hibernate... to their full power thanks to annotations and generics.

Posted by Guillaume Laforge on Jul 10, 2007 at 03:26 AM UTC - 5 hrs

@Sam/Guillaume, Thanks for the heads up as to the benefits of Groovy - I'll definitely give it another look. Only problem for me is that at one language a year I probably won't get to it before the JVM is deprecated :-< Ruby, Haskell, OCaml, D, Converge, Smalltalk . . .

Posted by Peter Bell on Jul 10, 2007 at 09:30 AM UTC - 5 hrs

I quite don't see the case for Yet Another Scripting Language (Groovy) in the situation there is a number of other, established, and also well-linked with Java. Just to add one other example to Ruby, there's Jython where I did not find any limitations compared to what Groovy is said to offer. Plus it has a huge Python library codebase available... I just don't see why to waste time on something not-so-mature as an existing language instead of reusing available resources if there's no real benefit.

Posted by Jindra Vavruska on Aug 08, 2007 at 07:25 AM UTC - 5 hrs

@Jindra, neither Jython nor JRuby can leverage features like annotations and generics. The day you'll need to interact with code or frameworks requiring those features, you'll be in trouble. When you need a dynamic language on the JVM and a very tight integration with the underlying platform, you'll quickly understand the advantages of using Groovy!

Regarding the "Yet Another Scripting Language" (apart from the fact Groovy is a *dynamic* language and not just a *scripting* language), imagine if nobody had ever invented a new language from time to time, you would still be coding in assembler on punch cards. Is it desirable? Can innovation still work if you have to wait for Java 7 to get closures? etc.

Final point regarding library codebases, well, Java has certainly the widest library codebase possible, and Groovy lets you leverage all this.

Posted by Guillaume Laforge on Aug 08, 2007 at 07:34 AM UTC - 5 hrs

At any rate, the sample snippet will give a groovy.lang.DeprecationException in versions > 1.5.0 Iterators on files are not supported anymore.

Posted by Leroy Sylvain on Feb 02, 2008 at 03:23 PM UTC - 5 hrs

Leave a comment

Leave this field empty
Your Name
Email (not displayed, more info?)


Subcribe to this comment thread
Remember my details

Picture of me

.NET (19)
AI/Machine Learning (14)
Answers To 100 Interview Questions (10)
Bioinformatics (2)
Business (1)
C and Cplusplus (6)
cfrails (22)
ColdFusion (78)
Customer Relations (15)
Databases (3)
DRY (18)
DSLs (11)
Future Tech (5)
Games (5)
Groovy/Grails (8)
Hardware (1)
IDEs (9)
Java (38)
JavaScript (4)
Linux (2)
Lisp (1)
Mac OS (4)
Management (15)
MediaServerX (1)
Miscellany (76)
OOAD (37)
Productivity (11)
Programming (168)
Programming Quotables (9)
Rails (31)
Ruby (67)
Save Your Job (58)
scriptaGulous (4)
Software Development Process (23)
TDD (41)
TDDing xorblog (6)
Tools (5)
Web Development (8)
Windows (1)
With (1)
YAGNI (10)

Agile Manifesto & Principles
Principles Of OOD
Ruby on Rails

RSS 2.0: Full Post | Short Blurb
Subscribe by email:

Delivered by FeedBurner