Recommendations for migrating from Java to Groovy

I understand Java and start experimenting with Groovy. Since the two are integrated so well, I find myself in Java for everything I can, because it is so simple. What specific advice can you offer that will speed up my work with Groovy?

Meaning - in which areas does groovy outperform java and where should I stick with Java?

+6
java groovy
source share
2 answers

Some of the main things that I like groovy for:

  • testing is probably the biggest win. The ability to change runtime behavior and bullying methods is one of the biggest things about groovy. Now convert the test packages to groovy.
  • use the creators. Groovy builders have much more expressiveness than traditional java. In particular, MarkupBuilder for embedded XML or HTML snippets is 1000 times better than vanilla java
  • GPars if you are doing any concurrent programming or threads

Also see Groovy Hidden Functions and Why you should use groovy over Java (note: it was "removed from for moderation reasons").

Where I will stick with java:

  • any place where speed is really important, stick with java. You still appreciate the performance dynamics of groovy.
+3
source share

The problem with Groovy.

Groovy is easy to write, but a nightmare to maintain. In my opinion, it should not be used in large projects. Inheriting someone else (or your own) code can be problematic because very often you don’t have the concept of a variable type, so you have the due diligence to learn or use the statements to guarantee the incoming type of the method.

Groovy is a weak language. The type of a variable is often ignored or "conveniently" executed automatically, which leads to numerous errors and lower performance.

Even the shortcomings of the IDE are absent, because there are almost faceless language variables. In many cases, compilation simply cannot know what a variable type is. Even if you declare a variable type (which helps the editor make suggestions), many programmers forget to determine the type of variables.

It has interesting ideas that I would like to see in Java, but stay away from it if your Groovy code needs more than a thousand lines.

* Answers in a nutshell * To summarize, here are the answers to both questions:

What specific advice can you offer? speed up my work with Groovy?

Use it only for small things. Otherwise, you incur a technical debt (see Wikipedia). While I'm in a similar situation. Testing modules, using the console to check code snippets, etc. - This is what will speed up your development, as it is so easy to learn and use. Remember to master the closure, collection, and loop, as well as understand which Java features are not available in Groovy.

Do not use pure Groovy for complex or large applications. In the long run, maintenance will slow you down.

Meaning - in which areas is groovy superior to java, and where should I stick to Java?

In a large or critical project, you need to be disciplined and use reliable tools. It's like building a house: I'm building a doll house, Groovy is great :-) ... if it's not perfect, it's not a biggie. If you are building your own home or something more with a small margin of error, you need to use high-quality tools and materials of the best quality that do not allow you to control potential problems (for example, Java).

In any case, Groovy looks like a duck tape: some here and there may not do much harm.

-2
source share

All Articles