How to earn your Clojure white belt
I tend to think that if I do not know how to implement something then I do not undestand completely how it works. That is why I want to…
I tend to think that if I do not know how to implement something then I do not undestand completely how it works. That is why I want to learn so many things: new frameworks, programming languages, garbage collectors, type systems, compilers, editors, operating systems, protocols, kernel development. The road to enlightenment is long and difficult. To make things worse, you need to invest time on keeping up to date with technologies you thought you already knew. I usually feel like Mario in one of those levels where he needs to jump between moving clouds to reach the finish line.
That is why one of the best skills to get is being able to separate the wheat from the chaff. We have finite time and distractions are infinite. If you are going to invest time in learning a new language then you should consider Lisp which is definitely wheat of the best quality. If you don’t know why, then go read Beating the Averages article. Clojure is a member of the Lisp family. If you have used a Lisp dialect such as Scheme, Common Lisp, Emacs Lisp, or even really alien and amazing creatures such Shen, LFE, Racket, Pixie you might ask yourself why you should be learning Clojure. This is my opinionated point of view:
- The language’s creator: Rich Hickey has a holistic understanding of this era development issues. You should read/watch his talks called Are We There Yet?, Simple Made Easy, The Language of the System. I see Clojure as a step in the right direction for tackling this era’s development issues
- Great functional programming support: First class functions, persistent, immutable data structures and lazy sequences. It has great support of polimorphism thanks to multimethods and protocols
- Concurrency support from its inception thanks to atoms, agents, refs, a software transactional memory system and asynchronous programming using channels a la CSP with core.async library
- Batteries included: good core libraries and transducers support
- Clojurescript: Clojure that targets JavaScript with great libraries such as reagent, an interface to React.js that is really simple and useful. Check David Nolen’s talks called ClojureScript: Lisp’s Revenge and Introduction to ClojureScript
- JVM’s power (available almost everyhwere, optimized garbage collector, JIT compilation, Java interoperability), but also some issues such as not being able to properly support tail call optimization and awful stacktraces. If you are a Java developer you should check part I and II from Rich Hickey’s Clojure for Java Programmers talk
Ready, steady, go!
Install Leiningen and configure your editor of choice.
- Emacs with Cider Clojure mode and Company mode
- Vim with vim-fireplace, im-sexp-mappings-for-regular-people, vim-salve, rainbow
- Light Table
- Nightcode
- Sublime with paredit, Lispindent and SublimeREPL
- Cursive (IntelliJ)
- Counterclockwise (Eclipse)
Good tools that deserve a mention
- Linter Eastwood
- Idiomatic Clojure checker kibit
- Clojure formatter cljfmt
- Check simple issues in your code bikeshed
Love at first sight
First of all get an idea of Clojure syntax and semantics:
- Learn X in Y minutes where X=clojure
- Clojure by example
- How I start Clojure
- Listen to Software Engineering Radio’s interview with Rich Hickey
If you do not understand something move on. At this stage the only objective is to grasp some basic ideas about Clojure.
Practice plus reading equals perfection
- First practice with the Koans
- Then read Clojure for the Brave and True, a simple and short book. If you prefer to watch videos, you can buy the course Introduction to Clojure from PurelyFunctionalTV.
- Practice again with 4clojure problems
- Follow the road to perfection with Clojure exercism
- Finish the practice with Wanderland Clojure Katas
It is always a good idea to have the cheatsheet at hand.
Other two good tutorials worth mentioning are Clojure from the ground up and Hitchhiker’s Guide to Clojure.
Idiomatic Clojure
Clojure is not Java, neither Common Lisp or Scheme. You should learn to write idiomatic Clojure. The Joy of Clojure is your best friend to become a native Clojure speaker:
It is also important to follow table manners or the Clojure style guide.
If you have trouble like me grasping macros, then you should also check out Mastering Clojure Macros.
Oh, if you miss your type checking then now it is a good time that you read about optional type system for Clojure.
Keep up to date
Know the full arsenal at your disposal
Get help
- Google Group
- IRC: #clojure channel in Freenode server
- Clojurians Slack
Introduction to Clojurescript
Clojure on the frontend trench:
Building your own Lisp
Building a Lisp is similar to a road trip with friends and good music but with no particular destination. Make yourself comfortable and enjoy the ride!