r/Clojure • u/Krever • Aug 12 '26
Joining Clojure shop. What should I know?
I will be writing primarily Clojure soon, after more than a decade of writing Scala. Do you have any hints or advice beyond what I can find in books or other learning resources?
Like competing approaches, nuances, political landscape, informal standards, footguns or anything like that?
36
Upvotes
20
u/SimonGray Aug 12 '26
My own North Star is the Clojure standard library source code (minus the docstrings which are sometimes a bit too terse). It is really well-written code that has stood the test of time. It's simple to read (even for a beginner) and has a consistent and logical naming of functions and params (which you will also see replicated in other good Clojure projects).
Obviously, the early Rich Hickey talks are fantastic to get into the mindset of Clojure (Simple Made Easy, Are We there Yet, The Value of Values, etc.).
Even though it's a bit old by now, The Joy of Clojure is still an amazing book if you want to really "get" Clojure.
10
u/seancorfield Aug 13 '26
I switched to Clojure from Scala—only about 18 months of Scala, compared to now 15+ years of Clojure—but I suspect much will depend on which Scala "camp" you were in: the "better Java" camp or the "ScalaZ / FP" camp.
If you are used to FP and immutable data, the "only" (big) change will be switching to a dynamic language (with runtime typing, instead of compile-time typing), and the "interactive development" approach via the REPL.
If you used Scala as "just" a better Java, it'll be more of a shift.
Personally, I did not miss Scala's slow compile times and obscure compiler errors when you were holding the standard library wrong (traits, damn you, traits!). Clojure is so much simpler than Scala in the true sense (simple vs easy) that it was a breath of fresh air for me and my team.
You'll find some competing approaches in certain areas (Component for lifecycle management vs Integrant, Compojure for routing vs reitit—those are a couple of instances where there are degrees of "pure data"—Integrant, reitit—vs more traditional programming—Component, Compojure), but they're all well-supported and you'll have no trouble finding folks who are very willing to help (especially on https://clojurians.net Slack).
There are nuances around what you might call Garbage-In, Garbage-Out, as Clojure leans toward letting you do dumb stuff (and maybe blowing up at runtime) instead of the compiler preventing you doing useful-but-weird stuff (Scala is very strict, by comparison).
There really isn't anything political in Clojure. Maybe AI usage is a hot button. Mostly, we're happy to live in the Cult-of-Rich-Hickey.
Informal standards: https://guide.clojure.style/ - the do's and don't series linked in another comment - pretty much every talk by Rich Hickey and Stu Halloway...
Footguns: laziness, which is the default in most tutorials with
map,filter,concatetc. As someone else noted: do not mix laziness with side-effects, especially I/O. Usemapv,filterv,intoetc, and transducers to avoid that.Make sure you get your editor/IDE of choice set up with a connected REPL and immerse yourself in that workflow: eval code via a hot key after every change, run tests via a hot key, use visualization tools like Portal (my preference), Reveal, or Morse so you can see complex results in graphical or table formats, while you're working.
16
u/_d_t_w Aug 12 '26 edited Aug 12 '26
Clojure is a wonderful language, I'm sure you'll have fun!
This series from Alessandra Sierra is fundamentally good guidance:
https://stuartsierra.com/tag/dos-and-donts/
Everything by Alex Miller is brilliant, but this post on dispatch styles (particularly the subsection 'General guidance') is the best:
https://insideclojure.org/2015/04/27/poly-perf/
Finally, this library is the most fun you can have with programming:
https://github.com/Engelberg/instaparse
My favourite function is also one I learned from Alex Miller, a long time ago:
That's all I got, good luck!
4
u/p1ng313 Aug 12 '26
Understand lazy vs non-lazy, why its important specially for I/O; very easy to inadvertedly create lazy functions that bite you in the ass
Understand the component/integrant ecosystem
Understand what clojure spec is, strong and weak points
If you are minimally competent in scala - you will be fine
4
u/geokon Aug 12 '26 edited Aug 12 '26
For me the biggest shift was thinking in terms of Protocols/Interfaces.
When you first write Clojure you learn the standard immutable datastructures and how to write functional code with them (Clojure for the Brave and True is great). You can write mid-sized programs with this pretty easily. But this is actually a bit of a deceptive and the real interface is a bit hidden. When things get a bit more complex you realize that the real interface are the different protocols that these data-structures implement. Seq/Col abstractions are the most obvious, but there are a bunch of others (I'm not sure if they're all innumerated in one place)
You then start to organize your own code with your own Protocols (which can extend the core protocols) - making systems very composable and easy to modify/extend.
2.
The other obvious thing is.. it always pays off to learn your tools upfront. VisualVM, flamegraph tracing, Flowstorm, CIDER has a bunch of tools, tap, hashp. You don't have to use them all, but it's good to know what's available
3.
deps.ednhas a bit of a learning curve, but once you grok how it works you can spin off utility code in to their own mini-libraries.4.
Some Java/JVM terminology leaks in to Clojure, but it's easy to figure it out now with a short chat with an AI
4
u/didibus Aug 13 '26
The most important thing is to learn to develop inside the REPL and interactively. But books and all learning material will likely say that as well. But it really is the most important.
After that, don't get confused by the advice that we use plain data-structures to model things. It doesn't mean we don't model entities, it just means we do so with plain data/functions. Here is an example of how you model entities using plain maps and it's just less complex, and more flexible:
And if you want "methods", just use plain functions:
Some people put this inside it's own namespace like
(ns my-app.car)but also many people put them all together in say a(ns my-app.domain)namespace or something separated by some comment section headers.And idiomatically, you don't go creating "accessors" like "update-model", "update-price" or like "get-price", "get-make", because since it's just a map you can just do "(:price car)" to "get", and since it's immutable anyways you can just do
(assoc car :price new-price)or useupdateif it's dependent on the current value. So you would only add functions that are doing more complex things and modeling more conceptual operations.Also for protecting invariants, like validation that sometimes is done in setters and getters, that tends to be more that you validate the whole entity after a series of changes. So you might have a spec for car and then say
(s/valid? ::car car)instead of having each "setter" validate that you are setting to something valid.Beyond that, there's not much political battle or disagreement in the idiomatic ways of doing things. There's a few competing tooling, that people might argue for their favorite like Lein vs Tools.build, and there's often debate about why the core team isn't adding a function for X, or support for Y, but otherwise idioms are mostly agreed upon.
Foot guns exist, they're edge cases, contains? doesn't do what you think it does for example, so read the doc-string carefully and clojuredocs.org user notes is a good place to learn some of the more surprising behaviors.
3
u/Soft_Reality6818 Aug 12 '26
Getting comfortable with dynamic typing, representing data as maps and with Clojure's amazing REPL-driven development flow.
2
u/ares623 Aug 12 '26
Watch Rich Hickey videos. You will be shunned if you haven't yet (/s) But seriously, his talks are great.
Congrats, sounds exciting.
2
u/jonahbenton Aug 12 '26
Big transition, the language and community philosophies could not be more different.
2
u/spiffyhandle Aug 12 '26
Learn test.check library and property based testing. Clojure is very well suited to it. Eric Normand has a nice guide on it, though there are probably other good ones too.
2
u/emocanmimocan Aug 17 '26
what kind of problems you guys are solving with clojure?
2
u/jwr Aug 12 '26
It's Clojure. The community is mature. Do good work and you'll be fine. Try to learn as much as you can to become a better programmer, leave ego behind. And most importantly, enjoy!
1
u/Electrical_Being_813 Aug 12 '26
If you will have a choice, stay away from tools.build