Why I decided to learn (and teach) Clojure
Tags: clojure, functional, java, programming
Published: 2023-03-20 13:06:24

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](https://www.oreilly.com/library/view/functional-thinking/9781449365509/) 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](https://elm-lang.org). 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](https://guide.elm-lang.org) and reading the [Elm in Action](https://www.manning.com/books/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](https://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](https://www.haskell.org). 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](http://learnyouahaskell.com)) 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](https://pt.wikipedia.org/wiki/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](https://www.youtube.com/watch?v=Uooh0Y9fC_M#t=4876ab_channel=IGN) or [this twit](https://twitter.com/ID_AA_Carmack/status/577877590070919168) by [John Carmack](https://pt.wikipedia.org/wiki/John_Carmack), founder of _id Software_). It felt mystical. And the fact that [Nubank adopted Clojure](https://building.nubank.com.br/working-with-clojure-at-nubank) 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](https://clojure.org|Clojure) and started reading the [Getting Clojure](https://pragprog.com/titles/roclojure/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](https://www.alura.com.br/formacao-clojure) (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](https://lisp-lang.org), [Clojure](https://clojure.org), [Scheme](https://groups.csail.mit.edu /mac/projects/scheme) and [Racket](https://racket-lang.org). So after deciding that I was going to learn Lisp, I had to choose one of its dialects.

[Clojure](https://clojure.org) 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](https://pt.wikipedia.org/wiki/Test-driven_development) together with [REPL Driven Development](https://practical.li/clojure/repl-driven-devlopment.html) (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](https://pragprog.com/titles/roclojure/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](https://www.braveclojure.com) book. Another option more focused on the foundations of the paradigm and that addresses languages ​​other than Clojure is the book [Functional Thinking](https://www.oreilly.com/library/view/functional-thinking/9781449365509/), by Neal Ford.

I created a [10 hours course on Introduction to Functional Programming with Clojure](https://segundatech.teachable.com) 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](https://segunda.tech/tags/english) and follow me on [twitter](https://twitter.com/marciofrayze).