Adam J Wolf Blog

Brain Freeze from Clojure

I am back to my endeavor to learn Clojure. This is a 2019 goal of mine. I've been getting a jump on my resolution in this confusing time between Christmas and New Years. What day is it? Do I need to go back to work yet?

When working through the chapters of Programming Clojure 3rd edition from the Pragmatic Programmers, I came across this example of converting some code from Java to Clojure and it struck me just how different they truly are. I am not saying one is better than the other, but I don't know how much further apart they could be; hence the brain freeze. 🤪

Java

Looks normal to me; how about you? My C# brain looks past the variable creation, mutable state, the multiple return sites and hones in on the setting of the "ch" variable and the inner "if" function.

Clojure

The Clojure code makes my brain freeze for a second or two like I am looking at a foreign language. The complete lack of mutable state, multiple return sites and no control flow structures are the most jarring.

Much of the difference of these two code blocks could be chalked up to the imperative vs. declarative styles but the contrast to me seems night and day. I am still very new to Clojure and I still have to unpack that "when" clause every time I look at the "index-filter" function.

I am definitely looking forward to learning more Clojure in 2019. I hope to train my brain to stop halting and start absorbing the declarative style and Clojure in the new year.

Adam J Wolf

Adam J Wolf

Hi, I'm Adam and I am a Principle Software Engineer at Emailage, husband, pit bull lover, sawdust maker, and Carhartt wearer. Welcome to my little place on the internet, If you ever have a question, please hit me up on Twitter.