The Clojurists hate me!
It is sometimes difficult to remember the path you took to reach proficiency. This makes it difficult to help others reach proficiency. I have this problem with Clojure. I’ve been using it for so long that I forget what I did to get better at it, other than just writing lots of code. (This is actually not a bad idea. Reading and writing lots of Clojure code is probably the best way to get better at writing Clojure code. Play golf with yourself. Solve the same problem over and over trying to use the fewest lines of code. Find an open source library and rewrite it from scratch on your own. Reading and writing lots of Clojure code a great way to get better at writing Clojure code, but that’s not my one weird trick.)
However, I do remember one decision I made that had a very positive impact on my Clojure skill. It only takes about an hour or two, and at the end you will accumulate an amazing amount of knowledge about how Clojure works and how you can use it effectively. It is a weird trick, and you have to be brave enough to do the unconventional. Here it is. Are you ready?
READ THE DOCS!
I’m not even joking! Go to this URL http://clojure.github.io/clojure/clojure.core-api.html and start reading from top to bottom. If you did not read through that page, you may not know about
amap. If you stopped reading before you get to ‘f’ you wouldn’t know about
frequencies. However, if you read all the way through, you will be rewarded with knowledge about
Imagine you had a sequence of data, and you wanted to count the number of occurrences of each unique value. You could spend a lot of time writing code, or you could just use
Now I recognize that it may not be immediately clear what a function does by reading its docstring. Here are three ways to fix that:
- While you’re reading the docs maintain an open REPL session and try any function that is not clear to you. Call it with a few different arguments. Poke it and try to figure out how it works.
- Hop over to ClojureDocs and look up the function. At ClojureDocs you’ll find examples that can provide illumination.
- Read the source for the function. If you click the “Source” link under a function it will send you to the GitHub repo and you can see how the function is implemented.
Pick one, or try all three. You can do this while you’re reading through the
clojure.core documentation, or you can just make note of functions that are not clear to you, then for 15 minutes every day take a function from your list an conquer it. Eventually that list will be empty! :)
Take the time to invest in yourself. Reading through the docs will give you a great overview of the possibilities of
clojure.core, and practicing with those function in the REPL will solidify that knowledge. The next time you are writing Clojure code, you will have easy access to the perfect function, right when you need it.