aspose file tools*
The moose likes Clojure and the fly likes Closure vs. Groovy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Clojure
Bookmark "Closure vs. Groovy" Watch "Closure vs. Groovy" New topic
Author

Closure vs. Groovy

Mike Gage
Greenhorn

Joined: Jan 22, 2002
Posts: 9
Is there an advantage to using Clojure rather than Groovy?
John Stevenson
author
Greenhorn

Joined: Mar 25, 2013
Posts: 7
    
    5
Mike Gage wrote:Is there an advantage to using Clojure rather than Groovy?


In many ways Clojure and Groovy are closer in syntax than Clojure and Java. If you take the Class definitions out of Groovy and just have functions, you would see many similarities in syntax. However, (please correct me if I am wrong), Grovvy is still based around an OOP approach rather than a functional programming approach. Not that you cant write functional code in Groovy I am sure, I just havent seen the language constructs that make it a natural thing to do. For parallelism, there is a great library for Groovy called GPars, but have not worked with this or looked at the code.

The immutable nature of Clojure is certainly different from what I understand of Groovy. With Clojure, immutable data structures (list, map, vector, set) are baked into the language. When you define one of these data structures (collectively know as sequences) it is immutable, you dont need to qualify it with anything else. In Groovy (and Java) you have to explicitly define something as immutable (using final / final static).

For example, if you create a list with the contents (a, b, c) then the contents of that list cant change. If you want to change that list then Clojure actually creates a new list for you under the covers, so anyone code still processing the original list will remain unaffected. You can change the names you use to reference a list, but the underlying list cant change.

Both Clojure and Groovy are dynamic and have a runtime environment (REPL). Use of the REPL is something that Clojure developers make use of heavily, I have not seen as much of this with Groovy developers, but that’s just my experience. Tooling support is good for both languages in IDE's such as Netbeans, Eclipse and Intellij. Many Clojure developers use Emacs or Vim as a lighter weight development environment that IDE's. Clojure and Groovy both have great build tools, Leiningen for Clojure and Graddle for Groovy (and other languages).

There are probably many similarities and differences between Clojure and Groovy, although my Groovy is a bit too rusty to offer a more in-depth comparison. I'd state that the main one is the paradigm each language uses, functional vs OOP.

Thank you
John Stevenson
chris webster
Bartender

Joined: Mar 01, 2009
Posts: 1479
    
  11

In practical terms, Groovy is very easy for a Java developer to adapt to, because the syntax is very similar but also very flexible, so you can write pure Java in Groovy - "Java-as-Groovy" - until you become more comfortable with idiomatic Groovy. Clojure, as a Lisp, is completely different so you need to take time to learn the basics - perhaps from a book like "Clojure Made Simple"!


No more Blub for me, thank you, Vicar.
Jacek Laskowski
Ranch Hand

Joined: Nov 06, 2005
Posts: 34

Mike Gage wrote:Is there an advantage to using Clojure rather than Groovy?


Hi,

My limited practical knowledge of Groovy gives me an impression that the language encourages writing imperative/procedural code while Clojure insists on functional style. While you can tackle same problems using imperative or functional paradigms, many are better suited for functional approach - list processing is the most notable one. When you extend the concept of list processing to sequence processing and the sequence is infinite, you need to think functionally where concepts like lazy sequences won't blow up your JVM.

Clojure gives you immutable structures and nice concurrent abstractions (vals, refs, atoms and agents). Once you use them in a project, you won't look back. Groovy is far from offering such abstractions, but it doesn't mean it's with no value - quite the contrary. Groovy excels at keeping Java devs in their comfort zone (imperative style) and gives them a functional flavour and dynamic typing.

There's definitely a place for both and in many cases it's a personal taste which language to pick for a project. The differences are often very subtle and tend to center around OOP vs functional paradigm.

Jacek


Jacek Laskowski - http://blog.japila.pl
Mike Gage
Greenhorn

Joined: Jan 22, 2002
Posts: 9
Interesting answers. I had once spent time learning the basics of Scala and found it interesting, but I never really used it in a useful way. I am just picking up Groovy now. It seems that it is somewhat like F# in the .NET world, in that you can write functional or object-oriented code or both.

Your answers are leading me toward putting Clojure on the list of languages to learn.

Thank you for your responses.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Closure vs. Groovy
 
Similar Threads
New tool for validate XML
JavaDeveloper or integrator of XML and support