I heard good things about Getting Clojure
, Programming Clojure
and Elements of Clojure
. I also think they complement each other, from what I heard. Getting Clojure is more introduction, Programming Clojure goes in more details, and Elements of Clojure is more phylosophical (design/structure of code). That said haven’t read them.
I do personally recommend Clojure, The Essential Reference
. It might not be best to learn Clojure at first, but once you know it somewhat, it’s great for deep diving further into every aspect of the core language.
I also really recommend at some point you read through the official Clojure overview, reference and guides:
And as a super quick intro like I want to get going in 30 minutes, I recommend the following small blog series:
It really depends, you kind of do whatever you want. Some people prefer throwing exceptions and use those, some people prefer returning errors (of various forms, could be returning exceptions as well, as opposed to throwing it).
That said, you’ll interop with Java a lot, and a lot of core functions are themselves just wrappers around Java, and Java will default to always throwing exceptions. That forces you to deal with this reality. Most popular libs I know of to do that are GitHub - adambard/failjure: Monadic error utilities for general use in Clojure(script) projects and Cats Documentation
So I’d say there’s an even mix of both.
I also want to say, I personally like thrown exceptions, I think a lot of programmers maybe don’t understand them, but they actually derived from the issues that return errors used to have. For keeping some code pure, you’ll need to return errors sometimes, but for impure code, exceptions are so much nicer I find. Letting you easily pick exactly where in the stack is most appropriate to retry, recover, log or publish a metric without poluting every function up the stack.with error branching, short-circuiting and re-returning. And exceptions capturing stack trace come in super handy for debugging, there’s so many times I wouldn’t have been able to find the root cause of an issue without the full trace.
But you need to follow this pattern to use them effectively:
- Every single procedure and function checks the sanity of its arguments and refuses to continue when the arguments are unreasonable, jumping out of the function.
- When calling out other functions, program functions only check for errors if they are in a position to react meaningfully.
- Error handling occurs at higher levels of function call chains, wherever it is meaningul to do so.
From: Exercises in programming styles book.
Just my 2 cents.
P.S.: In Clojure there’s also the condition restart way of handling errors such as with: GitHub - clojureman/special: Special (Conditions). A condition system for Clojure