A few weeks ago I started learning Clojure. My experience so far has been fantastic.
At SoCraTes 2015, I attended a great workshop on Haskell. While this is interesting if you are interested in learning functional programming, I found Haskell to be quite a pain. Not the language itself, but rather the environment. I spend too many hours trying to get proper IDE integration work work, and eventually decided to just try another language. Clojure has been on my to-try list for some time, and I’ve heard good things about it from several people I respect a lot. There are also a lot of really great talks by Rich Hickey, the creator of the language, on the internets. Together with the language being a LISP like Haskell, being influenced by it, being more modern, and having Java interoperability, those factors made me try out Clojure.
After getting Clojure, the first things I looked at where
- Can I execute something
- How do I get proper editor support
- How do I write and run a test
Unlike with Haskell, I did not get stuck with one of these steps, before even getting to writing actual code.
I got Curvive, which is a Clojure plugin for IntelliJ IDE. It has highlighting (doh) and many of the more advanced IDE features, such as refactorings. Clojure itself comes with testing tools, so you do not need to download some extra testing framework. To build projects and do various tasks such as running tests, there is Leiningen, which I found pretty simple to get started with.
To get started yourself, have a look at the excellent getting started section of the Clojure website.
I don’t quite recall how I found the Clojure Koans, though they are linked in the getting started section of the Clojure website. These Koans are a set of step by step exercises for learning Clojure. You start its test runner, and it will tell you there is something wrong with the First koan. After you solve the koan, it automatically moves on to the next. It runs every time you save, which makes things go really smooth.
After doing FizzBuzz, I figured I’d need to have a look through the Clojure documentation to get a feel of the language basics. At that point I had not actually looked at any such docs or indeed did anything real in a LISP dialect. Going through these Koans is an alternative that is a ton of fun, and probably teaches you the basics better than just staring at some docs. I managed them mostly unassisted, though at times needed to look up certain things. Halfway though the koans or so, I found the Clojure Koans Walkthrough, which was very helpful in explaining things in a bit more detail and in some cases showing me better ways to solve the koans than what I had come up with.
If you want to get started with Clojure, I highly recommend giving these koans a go. For more info, see the Clojure Koans website, which I found after completing the koans 🙂 You can look at my solutions to the koans, for which I made one commit per section.
After doing the koans I wanted to create some trivial application, to further learn Clojure, in particular to get out of the test environment bubble. I decided to create a little CLI application to convert numbers between arbitrary numerical systems that can be specified. This is something I did way back in my high school days, though then with a Visual Basic.Net GUI app called BN+ Converter Pro. You can find the Clojure code on GitHub and view the app in action on asciinema. The CLI UI is hardly smooth, though that is somewhat besides the point of the exercise.
Next I’d like to do some additional katas, and am planning to look at 4clojure. I’m also trying to come up with an idea for a simple-ish application that would solve some real world problem. For instance creating a Wikidata bot using the Wikidata Toolkit, which is written in Java.
“How to earn your Clojure white belt” is essentially a much better version of this blog post 🙂 There are many great talks on the ClojureTV YouTube channel, many of which are very interesting even when you have no intention of learning Clojure. And as I mentioned before, there are multiple awesome talks by Rich Hickey you can watch, of which “Simplicity Matters” is probably my favorite.