Why I decided to learn (and teach) Clojure

marciofrayze

Marcio Frayze

Posted on March 20, 2023

Why I decided to learn (and teach) Clojure

In 2017 I started to learn more about the universe of Functional Programming. This paradigm was gaining traction and most object-oriented programming languages ​​were adding more and more features inspired by this paradigm, including the language that I used the most: Java.

After the JDK 8 release in March 2014, it became common to hear Java developers using terms like: functional programming, streams, optional, map, flat map, etc. But many people around me still ignored these new features and, I confess, it took me a while to adopt them. The ideas sounded very interesting, but putting them into practice turned out to be more difficult than I expected.

After much trial and error, I decided to dig deeper into the concepts. The book Functional Thinking helped me take my first steps in the right direction.

In parallel I decided to learn a functional-first programming language instead of trying to partially apply the functional paradigm in an object-oriented language. After doing a lot of research, I chose to learn Elm. The fact that it is a pure and immutable functional language caught my attention. Also, it is focused on webapps development and, until then, I hadn't found any solution for developing web pages that I liked.

After going through the whole Introductory Guide to the Elm Language and reading the Elm in Action book, I already felt quite comfortable developing webapps in this paradigm. I liked Elm so much that I started a project to teach programming to beginners using this language and made the first classes available on the website elm.dev.br (in Brazilian Portuguese).

But there was a serious problem that I still had to face: Elm is a language designed for webapps development and works very well for that, but I was looking for a general purpose solution, that could also be used in backends development. So I started hunting for another language again.

Elm is a statically typed language inspired by Haskell. The natural step would be to use Elm on the frontend and Haskell on the backend. And that's what I tried to do. I read with some difficulty the Learn You a Haskell for Great Good! book (available for free here) and learned a lot of cool stuff. But creating a complete backend using Haskell proved to be more than I could chew. So I decided to look for alternatives...

During this whole process the word Lisp kept popping into my head! From time to time I would come across a video of someone influential in the community talking about it (like this video or this twit by John Carmack, founder of id Software). It felt mystical. And the fact that Nubank adopted Clojure brought a very real and pragmatic case study of the use of a Lisp dialect here in Brazil.

Until then I was postponing studying it because I was prioritizing statically typed languages ​​and the most famous dialects of Lisp are dynamic languages. But in early 2021 I finally decided to give it a chance. I chose the language Clojure and started reading the Getting Clojure book. Unlike my Haskell studies, I managed to read this book in just a few days! At the same time, I started taking Clojure classes at Alura (a popular online programming school in Brazil), which helped me to see how to program in this language in hands-on. It was a good combination: in the book I learned the concepts of the language more deeply and in the course I reviewed these concepts and learned the more practical parts.

Clojure's key features

Lisp is not a programming language, but a family of languages ​​with many dialects. The most famous dialects include Common Lisp, Clojure, Scheme and Racket. So after deciding that I was going to learn Lisp, I had to choose one of its dialects.

Clojure stood out to me for two reasons:

  • it uses the Java Virtual Machine, enabling interoperability with Java applications (which, as I said at the beginning of the article, is the language I usually use in the backend).
  • it predominantly uses the functional paradigm. Some Lisp dialects (like Common Lisp) are multiparadigm, but as my intention was to go deeper into the universe of functional programming, it made sense to adopt a dialect that was functional first.

The experience of programming in Clojure was quite liberating. Practice TDD together with REPL Driven Development (technique quite widespread inside the Clojure community) makes the feedback loop very fast. The fact that Clojure is a dynamic language also contributes to that.

Another characteristic of Clojure is that it is an impure language, that is, we can have side effects at any time. The main advantage of this is that it makes the language easier to learn (although it brings with it a host of other problems that don't happen in purer languages ​​like Elm or Haskell).

But although it is an impure language, it encourages a series of good practices that significantly reduces the potential problems of this approach.

Getting started with Clojure

Clojure might be intimidating at first, but after a few hours you get used to it's syntax and it's actually quite easy to learn. That's why I also chose this language to share with other developers the basic fundamentals of functional programming.

If books are your thing, I recommend starting with Getting Clojure, which as I said earlier, is a great way to understand the basic principles behind Clojure. But if you are looking for a free option, you may start with the online version of the Clojure for Brave and True book. Another option more focused on the foundations of the paradigm and that addresses languages ​​other than Clojure is the book Functional Thinking, by Neal Ford.

I created a 10 hours course on Introduction to Functional Programming with Clojure with optional payment (yes, you can enroll for free if you want to!). But right now it's only available in my native language: Brazilian Portuguese. 😉

And you, what is your favorite paradigm? Have you tried programming using the functional paradigm? What were your main difficulties? Share your experiences in the comments!


Did you like this text? Checkout my other articles at: https://segunda.tech/tags/english and follow me on twitter.

💖 💪 🙅 🚩
marciofrayze
Marcio Frayze

Posted on March 20, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related