Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices moving from Java to Groovy [closed]

Tags:

java

groovy

I'm versed in Java, and starting to experiment with Groovy. Because the two are integrated so well, I find myself writing in Java whatever I can because it's so easy. What specific tips can you offer that would speedup my work with Groovy?

Meaning - in what areas do groovy excel over java, and where should I stick to Java?

like image 915
ripper234 Avatar asked Oct 21 '10 08:10

ripper234


1 Answers

Some of the main things I like groovy for:

  • testing is probably the biggest win. The ability to change behavior at runtime and mock out methods is one of the greatest things about groovy. Convert your test suites to groovy now!
  • use the builders. Groovy builders have so much more expressiveness than traditional java. In particular, the MarkupBuilder for embedded snippets of XML or HTML is 1000s of times nicer to use than vanilla java
  • GPars if you're doing any sort of concurrent programming or threading

Also see Hidden features of Groovy and Why would one use Groovy over Java (note: was "removed from Stack Overflow for reasons of moderation").

Where I'd stick with java:

  • any place where speed really matters, stick with java. You still pay a high cost in performance for groovy's dynamic nature.
like image 124
ataylor Avatar answered Oct 02 '22 02:10

ataylor