avatar

Eduardo Vedes

Posted on 18th January 2022

Getting Started with Clojure(Script) – Eduardo’s Journey

news-paper Clojure | Inside Flexiana | News |

2022 is just beginning, Clojure was never as hipster and attractive as it is now, and I’ve decided it is time to share a bit of my quest on learning Clojure with you folks. At the same time, I’ll try to provide some guidance on how to get your feet wet with this amazing language.

A Bit of Context


What is Clojure?

As defined by its creator, Rich Hickey,

Clojure is a robust, practical, and fast programming language with a set of useful features that together form a simple, coherent, and powerful tool.

Among its main features I’d like to highlight:

  • Dynamic Development: Clojure is a dynamic environment you can interact with.
  • LISP: Clojure is a member of the Lisp family of languages.
  • Functional Programming: Clojure provides the tools to avoid mutable state, provides functions as first-class objects, and emphasizes recursive iteration instead of side-effect-based looping. Being impure, it still stands behind the philosophy that programs that are more functional are more robust.

Clojure was designed to be a hosted language and supports the dynamic implementation of Java interfaces and classes. All the code is compiled to JVM bytecode.

What is ClojureScript?

ClojureScript is a compiler for Clojure that targets JavaScript. It emits JavaScript code that is compatible with the advanced compilation mode of the Google Closure optimizing compiler.

This means that nowadays we’re able to produce code in Clojure that is ready to run in a browser. This is really helping a lot to leverage the usage of this amazing language.

Where am I coming from?

If you’re reading this article, chances are you’re already a professional programmer. But if not, just keep reading, this article is also for you, and maybe you can start your amazing journey into programming today!

I met Clojure for the first time in 2019. I was a JavaScript frontend developer working with JS/React/Node. Thanks to the great efforts of the JavaScript community and the React team, React/Redux started to leverage the best side of JavaScript, the functional one. And that’s when I started to pay attention to the functional paradigm.

I already had some experience with JavaScript pitfalls, mainly the lack of immutability, which can quickly lead you into some “not so funny” quirks.

One day I met a friend who convinced me to try Clojure, and I really enjoyed the experience. Clojure has almost no syntax, which makes it really quick to grok, and it’s one of the most high-level languages you can use. And I really mean it. Problems that are not very easy to solve in JavaScript, can quickly be solved in Clojure.

I must say that I already had knowledge of HTML, CSS, and JavaScript (specifically Node.js and React) on my toolbelt. And this really helped me get into Clojure quickly. But if you’re just beginning, no worries, you can learn it on the go.

Because ClojureScript compiles to JavaScript, knowing a bit of JavaScript can help you make use of already existent packages/solutions in the JavaScript ecosystem. Also, some ClojureScript frontend frameworks make use of React, so knowing React is also a plus to quickly grok how these frameworks work.

No matter where you’re coming from, where should you start learning Clojure?

Where should you start learning Clojure?

Well, first things first. I think you should know a bit about Rich Hickey and his motivation to create Clojure. That’s the best way to understand what’s behind the man and the language.

  • Are We There Yet? (2009): In this talk Rich Hickey advocated for the reexamination of basic principles like state, identity, value, time, types, genericity, complexity, as they are used by OOP today, to be able to create the new constructs and languages to deal with the massive parallelism and concurrency of the future.
  • Hammock Driven Development (2010): Rich Hickey talks about strategies he’s used personally for solving difficult problems. This is a more general talk, but will make you want to install a hammock in your office 😅
  • Simple Made Easy (2011): Rich Hickey emphasizes simplicity’s virtues over easiness, showing that while many choose easiness, they may end up with complexity, and the better way is to choose easiness along the simplicity path.
  • The Value of Values (2012): Rich Hickey compares value-oriented programming with place-oriented programming, concluding that the time of imperative languages has passed and it is the time of functional programming.

After getting through these videos, I’d definitely recommend you read the Love Letter To Clojure, from Gene Kim, and my favorite book of all time: Clojure for the Brave and True, a great pearl written by Daniel Higginbotham. It is free to read online, written with a great sense of humor, and guides you from zero to hero, raising awareness on the main aspects and functionalities of the language. Make sure you read it at least till the end of Part II.

At this point in time, you should be ready and anxious 😅 to get your hands dirty and start to tackle some challenges in Clojure.

Well, if you’re not proficient with Emacs, I’d recommend you go with VSCode. There’s a great addon for VSCode, called Calva, which will provide you with the essential tools to connect to or start a REPL. It also includes inline code evaluation, Paredit, code formatting, a test runner, syntax highlighting, linting, and more. It’s free to use, and it exists thanks to Peter Strömberg aka PEZ.

You might want to begin with some simple Clojure challenges. You can pick Rich 4Clojure and later Codewars.

Other important resources

By now, you might be already be able to tackle some Clojure challenges. Still, there are some obstacles in the way, such as tooling and frameworks.

To overcome this difficulty, I’ve completed some of Jacek Schae and Eric Normand’s (PuerlyFunctional.tv) courses, which are great. Eric Normand has an amazing newsletter, that inspires me every week, and also wrote a great book that helps a lot if you’re coming from JavaScript. It’s called Grokking Simplicity and it really helps you to think with a functional approach in mind.

Main difficulties along the journey

I think my journey to learn Clojure was pretty straightforward, although I had some small difficulties along the way.

My first obstacle was wanting to learn Emacs while learning Clojure. I totally recommend you to stick to your code editor, otherwise, there will be a lot of new things around and frustration can rise a bit. VS Code is an excellent option, as it is a very simple code editor. Plus, nowadays it provides you with great functionality and support for learning.

Also, the Clojure community is very mature, so don’t expect those very, very, beginner-friendly tutorials, where everything is explained step-by-step. The way I found to overcome this was to join Clojurians Slack. Despite being small, and mature, the Clojure community is very warm and happy to see someone new joining in. So, if you have any questions, don’t hesitate and feel free to post them there. Even those “not so dumb” questions are answered quickly and always with a very didactic approach.

You’ll be surprised as to how common it is for the creator of a library to directly answer you. This rocks, as you’re always talking with knowledgeable people, which are ready to teach and help you on a daily basis.

Last but not least, tooling got in my way a bit. More woth Clojure, than with ClojureScript, I found it a bit difficult to put all the pieces of the puzzle to build a backend. There are a lot of packages to mix and lots of new documentation to read. Watching Jacek Schae and Eric Normand’s courses provided great help with these difficulties, and that’s why I totally recommend tehm.

Conclusion

Learning Clojure was – and still is – a great and enjoyable adventure. I think almost everyone in the Clojure ecosystem has a very pleasant experience while writing code with it. First, because it’s a very high-level language. Second, because the functional approach saves you lots (and I really mean LOTS) of lines of code that would otherwise be needed to solve the same problem in another non-functional language such as JavaScript.

Have you already taken these steps and gained experience with Clojure? Check out Flexiana’s current job openings and apply to join our multinational team.