Getting Started in Clojure Meta-Guide

There are plenty of good guides for Clojure out there but they vary in learning styles and topics covered. Here I’m going to take you through the various guides you could use to make sure you’re not missing any gaps.

TL;DR

If you’re not entirely sure where best to start, you can’t go too far wrong by simply doing the following:

Useful references

While not necessarily the best way to learn in their own right, these references and cheat sheets are likely to be useful to refer back to during your learning journey.

  • Clojure Cheat Sheet - A handy summary of the Clojure core functions, categorised by usage
  • Learn X - Y Minutes, Where X = Clojure - Ostensibly a way to introduce you to Clojure, it is probably more useful as a good collection of simple examples while you are learning from more thorough tutorials.

Web-based ‘koan’ exercises

4ever-clojure - a rewrite of the now-defunct ‘4clojure’ site - gives you bite-size koan-style exercises, serving as a combined introduction and exercises to test your understanding.

This can be a great way to dip your toes into the language; it lets you start playing with Clojure without even needing to install anything on your local machine. It’s also very useful to come back to challenge yourself in bite-sized pieces.

Don’t feel like you need to complete all the challenges though. Where I gave up was where it got to challenges where you essentially have to re-implement core functions. While this can be a good test of your understanding, I felt it a bit similar to OO-style exercises of implementing a linked-list; an interesting test, but possibly more of an academic puzzle than something that truly teaches you things you’d likely use day-to-day.

Code editor

When you’re ready to start writing Clojure on your local machine, install Clojure and its related tooling from the steps in the “TL;DR section” above. Then you’ll be ready to get your editor set up.

If you’re not sure which editor to use you can safely follow the following advice taken from the Calva plugin’s documentation:

  • Pick something today and start writing Clojure.
  • Probably pick an editor you are familiar with already.
  • If you’re not familiar with any editor yet or you don’t have a strong allegiance to one, choose VS Code and Calva.
  • Switch to something else only if you encounter persistent annoyances that you can’t remove with plugins, code/config changes, help from the community, or more sleep

In particular, there are a lot of tutorials that advise you learn Emacs. This is because in Clojure’s early days it was the only editor with strong Clojure support, but nowadays Clojure support is much wider. While Emacs is certainly a solid choice for those who are happy to invest the time to learn it, learning both Clojure AND Emacs at the same time will almost certainly be overwhelming.

For writing Clojure code, you can choose amongst the following options:

  • VSCode with the Calva plugin - Its Clojure support has been maturing and is therefore on the rise in its popularity.
  • IntelliJ with the Cursive plugin - a great choice if you’re a Java developer who already uses IntelliJ.
  • Emacs with the Cider package - a very popular option in the Clojure community due to Emacs historically being a popular editor for Lisp dialects. Personally I use the Spacemacs distribution, for you can find a good getting started guide on Practicalli.
  • Vim with the Vim Iced plugin (which I hear is better than the fireplace plugin)

Whichever tool you pick, I recommend that you get familiar with the basics of structural editing modes such as paredit. You don’t need to learn all the commands from the start though - simply getting familiar with “slurping” and “barfing” will be plenty to start with.

The REPL

The REPL (Read-Eval-Print-Loop) is a very important feature of Clojure. While it is possible to develop Clojure without using it at all, you’ll probably get more out of Clojure once you get your head around it. You may already be familiar with languages such as Ruby or Python that have CLI REPLs. Clojure’s REPL is more powerful than those though, in short because:

  • Any good Clojure IDE will let you easily load your entire code repo into a REPL, allowing you to easily experiment with any function in any file
  • Clojure’s language design - in particular its great data literals, Functional Programming style and immutable data - make it easy to experiment with small parts of your program.

A slightly more negative reason to get familiar with the REPL is that sadly Clojure programs are rather slow to start. Therefore if you stick to a more traditional workflow of editing files and running unit tests via the command line, you’ll have to wait 10-20 seconds just for the Clojure runtime to start before the tests can run. In contrast, if you (re)run your code/tests from inside a REPL, you can get basically instantaneous feedback - faster even than interpreted languages such as Ruby or Python.

Resources for learning the REPL:

Guided Tutorials

With your environment & editor set up, you’re ready for getting deeper with more detailed guides.

Web

Clojure for the Brave and True by Daniel Higginbotham

https://www.braveclojure.com/clojure-for-the-brave-and-true/

This is probably the most popular tutorial out there for Clojure. This is the guide that I primarily followed when I was initially learning Clojure. In particular, it has a great section on how to write Clojure macros.

However, I hear that its humourous style is not to everyone’s taste.

Practicalli Clojure

https://practical.li/clojure/

More dry and technical than Clojure for the Brave and True, but many will prefer this style. More importantly, it has been updated according to newer Clojure releases.

On the minus side, it isn’t as cohesive as other tutorials; it often links out to other articles and videos. While helpful, this loses the tighter focus that other tutorials have.

Books

Living Clojure by Carin Meier

I haven’t read this book myself, but I’m familiar with other writing from Meier, who is a respected author in the Clojure community. She writes in an accessible style, while dialling down the humour a bit compared to Higginbotham.

Newer Clojure topics

The resources mentioned above are well-respected, and rightly so - but they sadly haven’t always kept up to date with additions to the Clojure language over the years. Here are some smaller, more focused guides to round-out your Clojure knowledge.

The Clojure ecosystem tends to favour libraries over frameworks. This is generally for the best, but it has the downside that it can be a bit overwhelming as a newcomer.

Thankfully, the post Production-Ready Clojure: show me the libraries! is a good recent (2023) post giving a rundown of the most commonly used & recommended libraries used today.

Spec

Clojure is a dynamic language, which has many advantages, but anything beyond a small system benefits well from some good data description and validation capabilities. Spec is the de facto standard for this.

Recommended guides & docs:

Test.check (Generative Testing)

One of the most powerful parts of Spec its data generation capabilities - especially when you combine it with Test.check, which in short is a sort of “fuzz-testing” library.

Please excuse the self-plug, but my own guide on Test.check should teach how you can take advantage of all your Spec definitions for generative testing.

Transducers

Transducers might sound complicated at first, but essentially they’re an alternative way to apply higher-order functions such as map and filter.

In particular:

  1. They’re more general, and can operate on things other than sequences
  2. They’re generally more performant, since they can avoid the overhead of multiple intermediary lazy sequences that are generated through multiple chained usages of higher order functions

The most helpful guide I’ve found for transducers is Grokking Clojure transducers by Eero Helenius; he does a fantastic job of explaining what they are and how they work from the ground up, as well as exploring the different ways in which you can use them.

The tap> function and Portal

Clojure 1.10 added the tap> and add-tap functions; a built-in data pipeline where you set up data receiver functions via add-tap, and send data to them using tap>.

You could use this functionality for production code, but personally I use it exclusively for debugging by sending debug data to the excellent Portal data visualiser tool.

Portal gives you a graphical, explorable log of all the data sent to it. In short, this gives you the flexibility and depth of graphical breakpoint-driven debugging data views, while avoiding the “stop the world” aspect, which can be problematic when testing asynchronous code.

For more info, see the GitHub page and this 30 minute intro video by the author.

Macros

As mentioned earlier, Clojure for the Brave and True has a great section on how to write Clojure macros. I highlight them as a separate topic here because I think they’re a little underused. Articles such as When To Use a Macro in Clojure rightly point out the dangers of over-using macros, but in my experience many Clojure devs have become too paranoid about using them. Learn how to use them, and when not to use them - but if you never try them at all you’re missing out on one of Clojure’s most powerful capabilities.

Babashka - a Clojure runtime suitable for scripting

We’ve discussed how Clojure sadly has a bit of a slow start-up time. In particular, this makes Clojure unsuited to small scripts which need to run fast.

Enter Babashka - a substantial subset of the Clojure language which runs on the Small Clojure Interpreter, meaning that you can write scripts written in Clojure that start up & run just as fast as Bash scripts.

The Babashka docs are very nice and clear, so check them out if you want to give it a try.

Motivation and Rationale

If you’re reading this article then clearly you’ve got at least a little motivation already to get started learning Clojure. However, if you need a bit more then it always helps to watch some videos by Rich Hickey, the creator of Clojure. His talks can help you understand why Clojure is designed the way it is and what language issues it aims to address.

Simple Made Easy

https://www.youtube.com/watch?v=LKtk3HCgTa8

A seminal video among Clojurians, as well as simply being very entertaining, so it’s highly recommended viewing for those learning Clojure. It’s a conceptual video which covers a few different high-level areas, including:

  • how we can write good/better programs
  • mistakes we can make in how we choose tools
  • how said thoughts inform the design of Clojure

In particular it (re)introduces the word “complect”, which is a term you will likely hear used by keen Clojurians.

Clojure, Made simple

https://youtu.be/028LZLUB24s?si=SiIgjVr31Hr6BkAB

A deeper look into how Clojure specifically addresses the simplicity concerns raised by Rich Hickey. Particularly cathartic if you are a long-suffering Java developer!.

Even more resources

There you have it, that’s my guided tour around what I’ve found (or heard) are the best Clojure learning resources.

For even more recommended Clojure materials, see An opinionated list of excellent Clojure learning materials (GitHub).