I was on vacation at the shore for the last week, and I resolved to learn at least one new thing. Halfway through the week, I decided that my new thing would be a new programming language. Since I have limited exposure to functional languages, I decided to go with one of those.
After surveying the landscape, I decided that Clojure would be my language of choice. Why Clojure? For one, it runs on the JVM and is able to take advantage of all the default Java/JVM tools and libraries. Other then that, it was mostly a random pick. Functional programming seems to be the new (old?) hotness these days, and there’s a ton of options. Many of them bring a lot of similar things to the table. In the end, I chose Clojure because it’s an evolution of Lisp, which is itself very similar to the MUSH/MUX code I spent much of my spare time writing in younger days.
I took a stab at Clojure by writing a simple telnet chat server, which is usually my go-to app for learning a new language.
Documentation for Clojure isn’t bad. I mainly used two sites: The Clojure Documentation Site and Mark Volkman’s Tutorial. I found a healthy mix of easy to advanced guides and examples to help me on my way.
My overall experience was pretty pleasant when it comes to programming in Clojure. I found myself struggling occasionally with finding alternatives to defining variables and maintaining application state, but I think that has less to do with Clojure itself and is more reflective of my inexperience with functional programming. Clojure syntax is fairly intuitive and easy to use when it comes to native Clojure concepts, but I found it a little less so when dealing with Java libraries.
I ended up relying on those Java libraries for a lot of input and output in my application, mainly due to the fact that I couldn’t find a socket library for Clojure. I also found myself falling back on Java threads for concurrency. Clojure offers some very nifty concurrency tools in the form of delays, futures, and promises, but none of them solved my need for long-running loops in a separate thread. I’m not sure if the use of native Java threads is intended when using Clojure, or if that was a result of my inexperience with the language. One thing I really enjoyed about concurrency in Clojure was the ready-to-use thread-safe reference types such as atoms and agents.
At the end of the day, I can definitely see the advantage of using Clojure (or any functional language) for certain purposes: specifically math computations and stuff that require lots of concurrency. I don’t know if Clojure will be a go-to for me in general outside of those two specific applications. I’ll have to take a stab at other functional languages in order to form a better opinion.