I sometimes get asked for recommendations of what programming tongue to "learn next". It's awesome that folks value the fact that being exposed to several sufficiently distinct programming languages is an crucial stage on the path to programming enlightenment. But it's additionally true that, stated constricted liberated time, the choice of which languages to study is important. As the celebrated citation by Alan Perlis says:
A tongue that doesn't power the way you think concerning programming, is not worth knowing.
In this article I desire to explain why I think Clojure is a terrific tongue for this task. Whatever your background, it's almost guaranteed to power the way you think about programming. It's a fairly new tongue (from 2007) that did a fine job of collecting insights and paradigms from many existing languages and organizing them into a coherent whole. It's chock-full of awesome ideas. In other words, the perfect tongue to develop your brain.

It's a Lisp!
First and foremost, Clojure belongs to the Lisp family of languages, akin Common Lisp, Scheme and Racket. Lisp is among the oldest and motionless most important families of programming languages to be acquainted with. Being a Lisp in this case means multiple things:
- Clojure is a energetic language. No matter anywhere you remain on the fixed vs. dynamic typing debate, knowing languages in the two camps is important. Clojure has a benevolent of optional typing, but in regulation it's dynamic.
- It promotes combinations of built-in data structures (lists, maps, vectors) over objects and has extremely fine reasons for doing so.
- It promotes programming alongside higher-order functions. Some built-in features like reducers and transducers rely heavily on composing higher command functions for transforming other functions.
- It has uniform syntax alongside complete Lisp-style macro support! This capability has proved to be extremely elusive for non-Lisp languages, and seeing several real macros in act is enlightening. Clojure has a entire Go-like CSP equivalent implemented using macros in core.async.
- It encourages REPL-based development, anywhere functionality is built and testsed gradually from the base up in an interactive terminal.
Importantly, Clojure is a extremely modern Lisp, alongside lots of libraries for tasks common in our day and age. It additionally builds upon crucial latest investigation in data structures, specified as productive persistent vectors, that lone appeared in the 1990s or later. I've been dabbling alongside assorted Lisps for nearly 15 years, and Clojure is the archetypal Lisp I'd regard using in production.
I desire the emphasis the importance of complete Lisp-style macros formerly again. Lisp's (and Clojure's) uniform syntax and macros power us to think concerning the Meta-circular abstraction - there's fair no way around it! We have to think of our code as data, and this has profound implications. Back in 2005, whenever I was motionless a programming neophyte, I faced a performance difficulty for a data-decoding program I was hacking on in Perl. Having learned several Lisp, I had the understanding of generating and evaluating new Perl code on the fly, which turned out to be key to the achievement of that program. I'm assured I could not have arrive up alongside that resolution rear afterward without being conscious of the "Lisp way".
Pragmatism and hard-won experience
The designers of Clojure are extremely pragmatic, construction upon decades of industry experience. I powerfully propose observing several YouTube videos of talks by foremost Clojure developers. In particular, observe a few of the additional famous talks by Rich Hickey - Clojure's original designer. The Alan Perlis citation mentioned complete may be his most popular, but there's another I discover at smallest as insightful:
Simplicity does not precede complexity, but follows it.
There's a certain norm in programmers I accept we can all recognize. It can only arrive from real, hard-won cognition of construction systems for many years and pondering concerning how to build specified systems additional efficiently next time. Rich Hickey certainly belongs to this norm category - his talks are very insightful, and this doctrine reigns in the scheme and implementation of Clojure, as fine as its (friendly and vibrant) community.
Sequences and laziness for mighty in-language data processing
Applications that procedure and extract helpful bits of data from large datasets all appearance alike in many programming languages, at smallest to several extent. What we really desire in many cases is SQL-like primitives built into our languages, but this is frequently challenging (.NET's LINQ is one example of a successful approach).
Clojure combines pervasive sequence protocols alongside persistent data structures and laziness to create this benevolent of project natural, using lone built-in tools. Here's a realistic example of a function taken from the Clojure Applied book:
(defn revenue-by-department [carts] (->> (filter :settled? carts) (mapcat :line-items) (map line-summary) (group-by :dept) (reduce-kv dept-total)))
All the functions used current are built-ins, including the ->> macro. This code says akin SQL and it's productive too. In fact, it can be made somewhat more productive and equal seamlessly parallelized using Reducers and Transducers.
The clojure.spec archive provides a degree of type-safety for nested data structures. If you've always written comments like "this maps strings to lists, anywhere all catalog component is a map of ...", clojure.spec makes it additional ceremonial and verifiable. This is extremely helpful when working alongside data, and is another example of anywhere Clojure's pragmatism shines; the tongue is energetic in its core, but whenever you need fixed checking - it's there, optionally (core.typed is another choice for a additional statically typed flavor).
The correct method to object-orientation
Historically, Lisp programmers weren't the biggest proponents of OOP. This doesn't average that OOP has entirely no value in Lisp-y languages, however. Common Lisp has had CLOS for decades, and Clojure additionally comes alongside an gathering of OO-like features.
That said, Clojure's sensation of OOP is particularly mighty and tends to discourage bad practices. Clojure uses "protocols", which are a benevolent of interfaces, and encourages thinking in conditions of protocols fairly than in terms of classes alongside bequest hierarchies, kind of akin Go. Add to that an ability to do true multiple dispatch and you have a mighty modeling tool at your fingertips.
Built-in assistance for concurrency and parallelism
It wouldn't be a genuine tongue of the 2000s without mighty assistance for concurrency and parallelism correct at the core. Clojure supports this in many ways, which are interleaved.
First, it's a functional tongue alongside persistent data structures. Persistent data structures are efficiently immutable, which makes them extremely appealing in a multi-threaded context. Clojure has a awesome implementation of persistent data structures equal for things akin vectors (which are fairly challenging to implement in an productive manner). This is a bigger agreement than may originally appear. Pure functions are frequently awesome in theory but neglect in custom because of too much copying of non-trivial data structures; Clojure's elegant use of persistent data structures solves this problem, making clean functions efficient and thus much additional applicable to a broad gathering of problems.
Second, Clojure doesn't fastener itself in the closet of purism and does support lower-level primitives for concurrency and mutation, anywhere needed. Atoms are built-in mutable province units alongside nuclear updates. Refs and transactions go further, implementing STM.
Third, Clojure comes alongside a bunch of concurrency tools built in. Promises, futures and threads leverage the underlying JVM's threading utilities.
Finally, Clojure has a beautiful fine implementation of Go's CSP in the core.async module. It provides two helpful things:
- Channels and Go select-like functionality (alts!!) which makes it easy to activity alongside harmless concurrent queues and "share data by communicating".
- go-blocks alongside non-blocking primitives that make it possible to compose cooperative "green threads" alongside ease.
Conclusion - try it
Finally, it's crucial to citation that Clojure is far from being an academic exercise. It's used in manufacturing by multiple companies, and has powerful roots in the enormous Java ecosystem. Clojure's interoperability alongside Java is seamless - Java code can be called from Clojure alongside no particular provisions, and all core Clojure entities are Java objects profound under the hood.
On the client side, Clojurescript has been gaining traction lately as another language-compiled-to-JS option. It brings the elegance of Clojure to client-side programming, among alongside several distinctive features akin core.async for callback-free concurrency.
This doesn't average that you should lone regard Clojure as a fit for your next project. On the contrary, I propose learning if equal if there's small chance of using it in manufacturing any period soon. In fact, this was exactly my situation, Clojure is a awesome tongue to develop your programming horizons; who knows, maybe in the forthcoming you'll discover it helpful for several genuine work. If you do, great! If you don't, learning it volition positively power how you use another programming languages.