Greasing the wheels of Java - What's up with all the hype on Ruby and Groovy?
Joined: Mar 06, 2007
I've been developing .Net applications and J2EE applications for a while now, but i've been quite away from scripting which seems to be a hype now, can this book introduce me to such technologies or is it an advanced level book? One needs to catch up with events.
Joined: Jan 28, 2008
From the table of contents, the first 3 chapters "Introduction", "Getting Started" and "New to Groovy" seem to be for real beginners. Even the description of the book on the book's page states that this book is for java professionals. I believe that this book requires absolutely no prior knowledge of groovy.
First of all, allow me to offer a gentle syntax correction... (wink) It's easy to dismiss Ruby, Groovy, et al, as "Just a scripting language" if you are so inclined. These languages are better described as "dynamic" languages. Groovy is "just as" compiled as Java is -- sometimes the Groovy interpreter does it for you on-the-fly, but you can just as easily call the "groovyc" and compile it yourself. (I'm assuming you meant no harm -- just having a bit of fun with you...)
Groovy offers a dramatic simplification of the Java language, while simultaneously offering you more power as well.
You mention doing web dev. If you having been looking into the RESTful revolution (REST is a modern form of web services that is slowly replacing legacy SOAP services), you'll find that Groovy really makes it easy. For example, let's say that you want to pull in the current weather conditions for your zipcode. The url is "http://weather.yahooapis.com/forecastrss?p=94089". The Groovy code to download the XML and store it in a String variable is as follows:
One line and you have the XML. (That URL class, BTW, is a standard java.net.URL class.) You can then use an XmlParser or an XmlSlurper (two Groovy libraries for parsing XML) to just as easily walk through the XML results.
The secret to Groovy's success is not reinventing the wheel -- it takes many of the standard JDK classes and dynamically adds new methods to them at runtime -- yes, even Final ones, so String gets a whole host of new functionality.
The hype/excitement about these new dynamic languages is all about their dramatic reduction of LOC coupled with their sophisticated metaprogramming capabilities.
You ask for a book recommendation, so I'll give you two...
My book (Groovy Recipes) is a very tactical book -- "How do I parse an RSS feed?" You get the short code snippet and a few supporting paragraphs. If you want to get in, get out, and get on with it, I think you'll enjoy it.
My good friend Venkat Subramaniam is releasing a book called Programming Groovy with the same publisher -- Pragmatic Bookshelf. His book is a much more strategic book -- he has whole chapters on metaprogramming, writing DSLs (Domain Specific Languages), unittesting, etc. I think that the two books are take a very yin/yang approach to the same language.