tags:

views:

111

answers:

3

Using my not-outstanding Google skills, I have not been able to find a decent tutorial on Groovy for Ruby programmers. There are a lot of political pieces (Ruby is great! Groovy is great!) and tiny little contrasts, but I really don't care which is better. I know Ruby (and Java) relatively well, and I'd like to learn Groovy.

Would anybody care to (either provide an amazing link or) mark some differences between the two languages in terms of how to do things (syntactic, class declaration, loops, blocks, etc.)? For my purposes you can assume full Java competence to explain.

Again, I am not interested in knowing which is better. Just need to know how to do stuff....

+2  A: 

Did you see this and this? Relatively short posts, I know. You're right; there doesn't appear to be much...

update: two more links.

Shadowfirebird
Hadn't seen those. Very cool.
Yar
+2  A: 

If you know Java, the best thing you can read is how the metaClass is used in Groovy. Here's a decent explanation: http://skillsmatter.com/downloads/Groovy%20User%20Group%20December%202006.pdf

Just remember that everything in Groovy runs through the metaClass. The seemingly simple statements:

a = foo.bar
bar = b
foo.baz(1,2,3)

Translate roughly into this Java:

a = foo.getMetaClass().getProperty("bar");
this.getMetaClass().setProperty("bar",b);
foo.getMetaClass().invokeMethod("baz",new Object[] {1,2,3});

Everything is dispatched through the metaClass, which is how pretty much all the Groovy "language" features work. The most important feature is probably closures. What you need to remember about closures is that it's all metaClass trickery. The closure's metaClass can be setup to try invoking methods/resolve properties on its delegate, which basically means you can do things like invoke a method on an object that doesn't have that method.

noah
Not an answer to the question, but helpful so +1 :)
Yar
A: 

The differences between Java and Groovy are less than the differences between Ruby and Groovy, so if you know both Ruby and Java, it probably makes more sense to look for a "Groovy for Java programmers" book or tutorial.

IMO, the best Groovy book on the market is Programming Groovy. It's the most up-to-date book that I know of (though still a few versions behind the latest release), is pretty concise, and covers some relatively advanced topics in quite a bit of detail (e.g. meta object protocol).

Don
Thanks Don, I'm going through an excellent book on Groovy right now, but there's more to life than learning. There's also remembering. I need a list of differences between Ruby and Groovy to keep them straight now and later. At some point I'll make the list, though, and put a link to it in this question.
Yar
As a matter of curiosity, what's the "excellent book on Groovy"?
Don