Clojure for beginners
- How to become truly productive in Clojure
- Learning Clojure
- Resources for beginners
- Beginner-friendly tools and starting packages
The key information, resources, community places, tools, and tricks you as a starting Clojure developer will find helpful.
(See the Clojure page for more and more general stuff.)
How to become truly productive in Clojure
You can be very productive with Clojure, much more than e.g. in Java thanks to its interactive development, simplicity, and powerful tools such as macros. However there are some preconditions, as Eric Normand writes in PurelyFunctional.tv Newsletter 266:
When you don’t have the stuff above (paren[these] management, integrated REPL, hot code reloading, and experience debugging the errors), the [development] cycle can be much slower than the descendants of punchcard languages.
Check out my post Clojure is in fact a trinity - of language, interactive development, and structural editing. |
So to really experience the productivity and pleasure of Clojure(Script), you need:
Learn and fully embrace REPL-driven development (and debugging). Don’t underestimate this, it is a fundamental shift of how you develop. Most people struggle with this mind shift for a while.
A tool to enable effective, productive (structural) editing of Clojure code, such as Parinfer (integrated in all popular Clojure editors)
A good editor with an integrated REPL so that you can evaluate your code and interact with your running application in a frictionless way. Cursive (paid for commercial use), VS Code with Calva, and Emacs (powerful but very steep and long learning curve) are the most popular. (Many editors have some Clojure support but the quality and depth and thus user experience vary a lot.)
ClojureScript: hot code reloading (which shadow-cljs does perfectly (together with everything else you might need for frontend development)).
Experience debugging errors - sadly you have to learn that though tools such as Ultra/Pretty (see below) and Expound for Spec do help. Pyro also looks great.
Not to hesitate to ask for help and advice at the Clojurians Slack community :-)
Understand Clojure philosophy and the Clojure way to approach and solve problems. Don’t try to apply what you learned in OOP/…, that would hurt. Understand the core principles and their benefits and downsides.
Learning Clojure
Learning Clojure is reportedly both easy and quick and a long-term process. New developers can start writing code within a few weeks but it might take months or years to master or Clojure core functions (you just keep stumbling on treasures in the core library) and to undo your OOP learning and start designing FP systems.
An opinionated list of excellent Clojure learning materials (added 2023/01) is an excellent list of organized, commented resources. Also matthewlisp/learn-clojure and Maarten Metz’s Clojure(Script) Learning Guide lists useful books, videos, courses, websites and tools. |
To learn Clojure, you need to explore multiple dimensions:
Learn to write code composed of functions that operate on data structures (maps and lists) - if you come from JavaScript then you are already good at this, the only difference being that Clojure data is "immutable"
Learn the syntax of Clojure - which is very simple and uniform. I have three short slides that cover most of the syntax. The online learning experience at maria.cloud provides an excellent, no-setup, minimal threshold, hands on introduction to the syntax (and some core functions).
Learn the rich clojure.core library. If you learned about 200 of the most common expressions (which covers more then functions) then you’d cover most code easily. See Eric Normand’s The 100 Most Used Clojure Expressions (results, PDF and data for the Anki learning app at the bottom).
Learn functional thinking and composing FP applications - here the focus is on distinguishing between data, calculations (pure functions), and actions (impure functions including side-effecting ones). Here Eric’s Grokking Simplicity - Taming complex software with functional thinking is an excellent resource. (It uses the familiar JS to teach the concepts).
Understand the philosophy of Clojure - which includes relentless focus on simplicity, stability, and dealing with an imperfect and changing word (that thus cannot be captured in static types). Here Joy of Clojure is a great resource. The talk Simple Made Easy (transcript with slides) by the author of Clojure is also a classic. As a bonus, his A History of Clojure (paper & talk) from 2021 might also be of interest.
Getting started
The free online book Clojure for the Brave and True has been highly recommended to me for beginners. To get your hands dirty, go through the programming exercises at 4clojure and/or through the even more beginner (and non-programmer) friendly Maria: learn Clojure with Shapes.
Always keep the Clojure Cheatsheet close by and read through it (and the referenced resources) regularly. Make sure to study the Programming at the REPL guide early on (and perhaps invest in Eric Normand’s video course Repl-Driven Development in Clojure; the first lesson is free, so check it out.)
I would also highly recommend reading the first chapter about Clojure philosophy from Joy of Clojure.
Last but not least: remember that you don’t need to learn all at once. You will most likely never need STM or agents (atoms are perfect for perhaps 99% state management needs, use core.async for non-trivial async needs) so feel free to skip those, at least for now. Datatypes and protocols and multimethods are something you will eventually need but you can likely get very far without them. Similarly, macros, transients, transducers, reducers, compilation and class generation can wait until you need them, certainly a few months.
The 14min video Clojure Syntax - The odd bits introduces the weird symbols of Clojure, such as ?
and !
in function names, *
around a var name, &
before an argument, #(some-fn …)
etc. It will make reading Clojure less confusing.
Leveling up
Ok, so you know the language and want to learn how to create systems and to deepen your understanding. Let’s get started!
Tip: A gradual approach works best. Don’t try to learn too much at once. Start with a simple, Clojure-only server, perhaps only using Ring and Hiccup and nothing more. Then add a routing library, … . Integrate with a database and/or an external API. Only when you are really comfortable with this, start with ClojureScript and its complexities. Personally I recommend using ClojureScript with shadow-cljs because it is an all-in-one tool (build, REPL, …) focused on developer ergonomics, with a great documentation and active support. Start perhaps with a simple React wrapper such as Reagent.
Books
Clojure Applied: From Practice to Practitioner by Ben Vandgrift, Alex Miller (2015) - even in 2019 this is the best and still highly relevant book about building systems in Clojure, tackling topics such as namespace organization, creating and connecting components, composing applications, handling configuration.
Elements of Clojure by Zachary Tellman (2018) - “It provides a framework for making better design choices, and a vocabulary for teams to discuss the software they collaborate on.”
Programming Clojure 3rd edition by Alex Miller, Stuart Halloway, Aaron Bedra (2018) - a handy, comprehensive reference
See all Clojure books at the Clojure site.
Reading code
A great way to learn is by studying code.
seancorfield/usermanager-example - This is a simple web application using Component, Ring, Compojure, and Selmer connected to a local SQLite database. Intended as a demonstration for beginners.
cljdoc - the code for Cljdoc.org. Beware that this is a little complex production application, with a database, batch jobs, and public APIs. Perhaps not the first thing to look at :)
next.jdbc - a Clojure wrapper for JDBC, created in 2019 to replace clojure/java.jdbc based on many years of experiences with maintaining and developing it, by a very skilled developer.
Asami - I find the code of this graph database by Paula very well written an documented. Some parts of it are focused on top performance instead of readability but nonetheless it is a good place to learn.
Resources for beginners
Official sources
Clojure.org and its References and Guides.
Especially the Programming at the REPL guide is essential
ClojureScript.org and its References and Guides.
Help & learning
ClojureDocs - the language function documentation with examples
cljdoc - documentation and API docs of Clojure libraries
Community-driven documentation site for the Clojure programming language - Tutorials aimed at new users, guides, and more
4clojure - learn Clojure by solving small task and comparing your solution with others (you may also like Clojure koans)
Maria: learn Clojure with Shapes - a cool, beginner-friendly ClojureScript notebook-style editor with a built-in introduction to Clojure(Script) using graphical programming
Community, advice, fora
Clojurians - the official Slack organization with channels for Clojure, ClojureScript, and most popular libraries and topics. Leading developers and authors often answer questions.
Clojure and ClojureScript Google Groups - for advice, announcements, keeping informed
Clojureverse - friendly discussion fora
Newsletters to keep updated about the latest development, useful libraries, etc.
The REPL by Daniel Compton (older issues)
PurelyFunctional.tv Newsletter by Eric Normand (older issues)
Podcasts
Beginner-friendly tools and starting packages
Beginner-friendly, all-in-one. getting-started IDEs: Nightcode and (simpler, web-based) Lightmod
Professional dev environments: The most popular tools for developing in Clojure(Script) are Emacs with Cider and IntelliJ with Cursive. But people also use VS Code with Calva (and Bracket Pair Colorizer) and Atom with Chlorine.
Web dev: Luminus is the recommended web “framework,” i.e. a curated and integrated set of libraries for web (backend and frontend) development in Clojure(Script) (developer tools, logging, security etc). So that you don’t need to assemble your own.
Editing code
Parinfer - provides for efficient and simple structural editing of Clojure/Lisp code using just Tab (compared to the older Paredit with its numerous key-bindings). A must-have for efficient and productive experience with any Lisp.
Building and running code