Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages of Clojure [closed]

Tags:

clojure

Can somebody point out the advantages of Clojure and what type of applications is it suited for ?

I don't intend to compare it to any languages as such. As a language in itself what is it suitable for ? My intention is to know the right tools for the right job, and where does clojure fit-in in that kind of scenario.

like image 439
Rishav Rastogi Avatar asked Jun 15 '10 15:06

Rishav Rastogi


People also ask

Why did you stop using Clojure?

It uses a lot of memory. It's hard to hire developers for it. It doesn't have enough Clojure based libraries and frameworks (i.e. Not interop based) The Lisp syntax is hard to read and unfamiliar.

What is the purpose of Clojure?

Clojure is designed to be a hosted language, sharing the JVM type system, GC, threads etc. All functions are compiled to JVM bytecode. Clojure is a great Java library consumer, offering the dot-target-member notation for calls to Java. Clojure supports the dynamic implementation of Java interfaces and classes.

Why is Clojure loved?

A big reason is that it's a LISP programming language, which I had never used before. Another reason is that Clojure is a functional programming language that embraces and encourages immutability, which means that you're not allowed to mutate variables, which is another thing I've never been exposed to before.


2 Answers

Advantages:

  • all the benefits of functional programming, without the purity straitjacket
  • lispy: allows dynamic, compact code with late binding, macros, multimethods
  • Java interoperability
  • can code functions to sequence abstraction instead of to specific data structures
  • concurrency goodies baked in: functional data structures, software transactional memory
  • runs on the JVM: portability and fast garbage collection

Suited for:

  • bottom-up design
  • embedded languages
  • highly-concurrent applications

Probably not suited for:

  • cases where you want static typing
  • if you want the language to be amenable to static analysis
  • anything that needs a fast startup time
  • hordes of clueless Java monkeys
like image 128
Nathan Hughes Avatar answered Oct 17 '22 05:10

Nathan Hughes


In general I find as strong points for clojure (in no particular order):

1) The REPL to try things out interactively.

2) Everything is immutable by default and mutability has several well chosen standard patterns to modify state in a safe way in an multithreaded environment

3) Tail recursion is made explicit. Till there is proper support for tail recursion on the JVM this is probably the best compromise

4) Very expressive language which favors a functional approach over an imperative approach.

5) Very good integration with the Java platform making it painless to mix in Java libraries

6) Leiningen as a build and dependency management tool together with the clojars site

Ok, point 6 has nothing to do with the language perse, but definitely with my enjoyment of using it.

Regarding applications it targets multithreading applications, but the way things go right now that could mean about anything, as everywhere people try to keep all those cores busy while the user is not waiting. On the other hand apparently a lot of people use it to deploy to Google App Engine which is radically SINGLE threaded.

The functional approach works well in my (limited) experience for implementing data transformations and calculations. Where information and events can be 'streamed' through the application. Web apps fall largely under this category where we "transform" a request into a "response".

But I still have to use it in real production code. Currently I use it for personal projects and prototyping/benchmarking stuff.

like image 45
Peter Tillemans Avatar answered Oct 17 '22 06:10

Peter Tillemans