Win a copy of Fixing your Scrum this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Closure vs. Groovy

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there an advantage to using Clojure rather than Groovy?
 
author
Posts: 7
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"!
 
Ranch Hand
Posts: 44
Scala Mac OS X IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Mike Gage
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic