wood burning stoves 2.0*
The moose likes Groovy and the fly likes When to use Java when to use Groovy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "When to use Java when to use Groovy" Watch "When to use Java when to use Groovy" New topic
Author

When to use Java when to use Groovy

Klaus Meucht
Greenhorn

Joined: Jul 24, 2004
Posts: 13
I have no experiance with using a scripting language directly in Java.

If I mix java and groovy, doesn't it produce code that is really hard to detect duplicated code?

Can a code coverage tool like CLOVER, detect the coverage of Groovy code?
Makes it sense to use Groovy only for Test Classes and MockObjects and let the production code in plain java?

If a developer is not familiar in Groovy, how easy is it for him to understand the code?
Dierk König
author
Ranch Hand

Joined: Nov 01, 2006
Posts: 43
Hi,

How do you detect duplicated code in Java? with PMD/CPD? This works well across Groovy and Java.

You can measure Groovy code coverage on source lines level, eg. with Cobertura. The book describes how.

Groovy makes sense for testing Java, but "only" would be far too limiting! ;-)

> If a developer is not familiar in Groovy, how easy is it for him to understand the code?

I don't know. Do you understand

println 'hi'

?

regards
Dierk
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Dierk K�nig:

> If a developer is not familiar in Groovy, how easy is it for him to understand the code?

I don't know. Do you understand

println 'hi'

?


I don't think understanding println 'hi' is a fair assumption that Groovy is easy for a java developer to understand. Closures, for example, are proving difficult for me to wrap my head around since this isn't something that a typical Java developer might be familiar with.

But I do believe Groovy to be easier to understand as a Java developer than another scripting language all together (Ruby, Python, etc).


GenRocket - Experts at Building Test Data
Dierk König
author
Ranch Hand

Joined: Nov 01, 2006
Posts: 43
the code

new File('test.txt').eachLine { line -> println line }

uses a closure. Is it hard to understand?
I don't think so.

Of course, you can write any kind of code, code that is easy to understand and very complicated code in any language.

Groovy tries to build on the knowledge and perspective of a Java programmer. But of course to fully leverage its features you also have to learn. That's what the book is for.

ciao
Dierk
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

So, theorically I can use Java and Groovy interchangeably ?
Can I use Groovy completely to develope EGB ? (Enterprise GroovyBeans, inspired by Gregg's Gwing )
Or even to develope a framework like Hibernate, Tapestry or Spring ?
Tug Wilson
Ranch Hand

Joined: Dec 12, 2006
Posts: 33
So, theorically I can use Java and Groovy interchangeably ?
Can I use Groovy completely to develope EGB ? (Enterprise GroovyBeans, inspired by Gregg's Gwing )
Or even to develope a framework like Hibernate, Tapestry or Spring ?


Yes - We already have Groovelets (which are Groovy Sevlets) and GSPs (can you guess what they are? )
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

GSPs (can you guess what they are? )

Global System for Positioning
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When to use Java when to use Groovy