Learning Clojure
I still find it hard to believe, but last 7 days I spent on learning Clojure. Yes, this esoteric language where everything is wrapped with (parenthesis).
I have a lot of thoughts about this “Learning Clojure” experience and it seems I’ll be exploring this new world for some time - that’s why I decided to split it into few parts (this agenda may change over time while I’m exploring it):
- (this post) Why did I decide to learn Clojure? - giving you an overview what dragged me to this rabbit hole
- Setting up an environment for Clojure development
- Rushing through Advent of Code and reading The Joy of Clojure
- Getting familiar with Clojure ways of building software
- Is it really state that makes software complex?
- Things I don’t like about Clojure
- Things that impressed me when learning Clojure
Why to learn new programming language?
I was about to write this section when I saw this post on hacker news: Why care about programming languages.
Yes, in short, in every language there are many different concepts embbedded. Few from top of my head:
C, C++ -> malloc, pointers, caring about memory in general Java -> Object Oriented Programming, Garbage Collector CSS, SQL -> Declarative programming Scala -> Functional, implicit (Agent Model) Groovy -> How expressive it can be! Typescript -> XState, Rich type system Python -> pseudocode can just work Kotlin -> Rich DSL, extensions
One thing I would add: languages have different communities. It’s fun to see how they differ and how they approach different things. I think that Clojure one rarely attracts beginners. When I read discussions on some forums on the Internet - looks like these people really spent lot of time thinking about software creation, whereas in Python / Javacript there is a lot of people who just want to make something work without thinking too much.
Why do I choose Clojure among all others?
Every time I was hearing about Clojure I was:
- Surprised that anybody could come up with such ugly syntax
- Remembering a discussion with Clojure developers who were proud who they can use REPL on their production system and do debugging on real traffic
So it was just weird to learn more about it.
I don’t remember how I ended up watching Simple Made Easy by Rich Hickey. This presentation resonated with me so much! I thought - this guy got it right and he can deliver his understanding so well! So I started watching his other talks:
After that I knew, that I need to at least play a bit with this weird language and see what I’m missing.
One quote that made me laugh especially:
“The hardest part about evangelizing Clojure to Java developers is that you’re trying to sell them a solution to a problem they don’t know they have.”
~ Rich Hickey
If you don’t have spare 4 hours to watch above, I’ll give you TL;DR of main concepts:
- State is a root cause of complexity. Data, Functions (transformations of data) and State should state separate
- State is Identity + Value + Time (so particular value is attached to identity and it changes over time)
- Having objects that have mutable state inside is ridicolous (he explores it even deeper in The Value of Values) - and when they interact with each other - it’s a chaos
- Testing pure functions is easy (everytime the same output for given input). Testing system with side effects is very hard
- That’s why we should strive for most of our program to be pure and push side effects to the edges
- Design is a process where you move your understanding forward (it’s usually shared understanding between many people and it’s written down)
- When you make decision - it’s crucial to determine what dimensions we are comparing together, how people solve the problem currently and what other options we have on the table
Other argument for this particular language: Clojure seems to attract already experienced engineers who looks for solutions after being burnt with real world systems. It’s not beginner friendly. It’s not very popular. However, it may be a good thing.
Stay tuned for next blog posts in this serie!
Comments