Z
Z
zilopop2012-06-05 15:19:38
Java
zilopop, 2012-06-05 15:19:38

How do you use Groovy in your Java project?

I don't know much about Groovy yet, so I really have two questions:
1. I'd like to hear about your experience with Groovy as part of your Java application. Perhaps these are only domain objects, or business logic, perhaps both. In particular, I'm wondering if it's possible to use Groovy for the entire project, or only for those parts that can not greatly affect performance?
2. The following test prompted me to the first question: I implemented the simplest recursive algorithm for calculating Fibonacci numbers in Java and Groovy and measured its running time.
The code:

class Groovy {

  def fibonacci(n) {
    
    if (n < 2) return n
    
    return fibonacci(n - 1) + fibonacci(n - 2) 
  }
  
}

public class Java {

  public int fibonacci(int n) {
    
    if (n < 2) return n;

    return fibonacci(n - 1) + fibonacci(n - 2);
  }
  
}

I expected about the same execution time, but in practice I got the following:
для n = 40<br/>
<br/>
Java: 0.481 сек.<br/>
Groovy: 6.992 сек.<br/>

What explains such a gap?

Answer the question

In order to leave comments, you need to log in

9 answer(s)
S
Snowindy, 2012-06-05
@Snowwindy

We use for scripts validating system output. Test cases and validating scripts are written by testers.
All paths to validation scripts are configured through the database, so the development team does not interfere much with autotests.
Testers also write code for SoapUI mocks, Groovy is also used there.

S
Snowindy, 2012-06-05
@Snowwindy

In another project, we are seriously using Groovy scripts inside a docx document to generate contracts in docx format.
I even specifically wrote a library in the public domain. snowindy.github.com/scriptlet4docx
And of course Grails sites.

J
javax, 2012-06-05
@javax

1. For writing unit tests
2. For scripts that need Java libraries (for example, starting our server)

I
ivnik, 2012-06-05
@ivnik

What version of jvm did you use? Try 1.7, it has invoke dynamic which should speed up groovy scripts (and also use the latest version of groovy).
In general, the groove code is unlikely to work as fast as the java code, if it works 2 times slower, it's already good.

D
dbmaster, 2012-06-06
@dbmaster

Use to take out business logic that can be changed by the user
Use for plugins dbmaster.org/plugins

S
sha1dy, 2012-06-09
@sha1dy

* DSL for scripting the application's business logic (Java/Scala)
* Build and deploy scripts (gradle)
* Acceptance tests that write QA It
's better to write an application in Scala IMHO if Java doesn't suit you. And if you want to try a dynamic language, then Ruby is better, from which Groovy copied a lot of features (but looks much worse than in Ruby)

S
SmoggIT, 2012-06-10
@SmoggIT

We are just starting to use
- Tests, logic for tests
- Scripts
- DSL
- Little things, for example, we try Gradle

M
monzdrpower, 2012-06-22
@monzdrpower

Started with simple regexp, work with xml, tests. Then came full-fledged services, import utilities, and so on.
Now the groove code already makes up the majority of the application, we write all the new functionality in groove, everything is so inconvenient in Java :)
We have a workflow system, so the speed of work is not critical.
My article on integration
habrahabr.ru/post/145158/

A
AnyKey80lvl, 2018-02-15
@AnyKey80lvl

We write all our projects for the needs of system integration in groovy, using grails.
Happy as elephants.
We write rare small parts in Java to increase performance, although Groovy speed is enough for us.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question