Answer the question
In order to leave comments, you need to log in
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);
}
}
для n = 40<br/>
<br/>
Java: 0.481 сек.<br/>
Groovy: 6.992 сек.<br/>
Answer the question
In order to leave comments, you need to log in
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.
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.
1. For writing unit tests
2. For scripts that need Java libraries (for example, starting our server)
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.
Use to take out business logic that can be changed by the user
Use for plugins dbmaster.org/plugins
* 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)
We are just starting to use
- Tests, logic for tests
- Scripts
- DSL
- Little things, for example, we try Gradle
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/
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 questionAsk a Question
731 491 924 answers to any question