Moving from Non-Java-Ruby to Groovy: Language Differences

Using my outstanding Google skills, I couldn't find a decent Groovy tutorial for Ruby programmers. There are a lot of political works (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 would like to learn Groovy.

Will anyone care (either provide an awesome link, or) point out some differences between the two languages ​​in terms of how to do things (syntax, class declarations, loops, blocks, etc.)? For my purposes, you can assume the full competence of Java for an explanation.

Again, I am not interested in knowing which is better. You just need to know how to do things ....

+4
source share
5 answers

Have you seen this and this ? Relatively short posts, I know. You're right; there seems to be not much ...

update: two more links .

+2
source

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

Just remember that everything in Groovy goes through metaClass. Apparently simple statements:

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

Translate roughly to this Java:

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

Everything is sent via metaClass, since almost all Groovy functions work. The most important feature is probably closure . What you need to remember about closures is that it all tricks metaClass. The metaClass utility can be configured to try to call the / allow properties for your delegate, which basically means that you can do things like calling a method on an object that does not have this method.

+5
source

We need more questions like this. Three years after the question, there is still a comparative lack of information about this movement between these two similar languages.

I found this slide slide presentation that covers many major places.

And this blog post was useful with “simple” stuff because it gives a little more background:

The reasons for switching between languages ​​usually have more in common with the needs of the project than the language itself, and I feel that it is important for sharing and comparing between tools.

One standard resource for these kinds of questions: Rosetta Code .

Hope to see some more tips added to this list.

Cheers, Will

+2
source

The differences between Java and Groovy are less than the differences between Ruby and Groovy, so if you know how Ruby and Java it probably makes sense to look for the Groovy for Java Programmers book or tutorial.

IMO, the best Groovy book on the market Groovy Programming . This is the most modern book that I know about (although there are still several versions behind the latest version), it is rather brief and in some detail describes some relatively advanced topics (for example, the protocol of meta objects).

+1
source

The Groovy wiki has a good article called Groovy style and language guidelines for Java developers .

0
source

Source: https://habr.com/ru/post/1301150/


All Articles