Why should I choose Clojure over another language for a new project? In what areas does it excel?
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.
Clojure meets its goals by: embracing an industry-standard, open platform - the JVM; modernizing a venerable language - Lisp; fostering functional programming with immutable persistent data structures; and providing built-in concurrency support via software transactional memory and asynchronous agents.
All our models, datastores, and services are built in Clojure. We find that Clojure's support for parallelism makes it easy to run complex models with low latency. Precursor is real-time collaborative prototyping for teams built with Clojure, ClojureScript, and Datomic.
In programming languages, a closure, also lexical closure or function closure, is a technique for implementing lexically scoped name binding in a language with first-class functions. Operationally, a closure is a record storing a function together with an environment.
Some scenarios where I would use Clojure:
You are building a new, highly concurrent application that needs to scale reliably. In my opinion, Clojure's concurrency features (STM, immutability-by-default, lock free MVCC) are the best of any major language at present. Rick Hickey's excellent video about Identity and State is a great way to get a feeling for this.
You are a Java-based shop that wants a productive dynamic language that can be used for rapid development or scripting while maintaining your investment in a large Java code base. I've found Clojure pretty effective at "gluing together" Java code since the interop capabilities are extremely good (and simple!).
If you want to use a functional programming language Clojure is pretty good (it's not quite as "pure" as Haskell but has all the key features - first class functions, higher order function composition, immutability, laziness)
If you work in a field where there is a major need for code manipulation (compilers, DSLs, natural language processing, genetic programming), where the LISP "code is data" philosophy enables you to be extremely productive. This is a sweet spot for homoiconic LISP based languages in general.
At the risk of providing exactly the sort of reductive non-answer that Devin is referring to: I chose Clojure because I like the functional programming style and Clojure lets me do that on the JVM and interop with lots of existing code that runs on the JVM.
So the question then becomes: Why functional programming?
Immutable state - lack of side-effects, easier testing, better support for concurrency (and, in future, parallelism).
Small, functional components that can be easily reused and composed to construct large, flexible systems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With