I learnt a lot today as I paired with Chris on the minimax problem in Clojure.
The biggest hurdle so far in my Clojure journey, this language has made me feel uncomfortable. Inferior, embarrassed, question my ability to develop software.
Because of this learning Clojure during my apprentice has been one of the most beneficial times.
As I leave this language and move on to Ruby next week.
Here are a couple things that I’ve learnt.
1.Immutability is important
Having immutable data structures at first was difficult but now I see the benefits.
With immutability the rug isn’t being moved underneath you. If a data structure, let say a list is ‘(1 2 3 4), it stays ‘(1 2 3 4). It doesn’t matter what happens to it in the course of it’s life, if you use it anywhere, it’s always going to be ‘(1 2 3 4). The thought of going to other languages where if you send a piece of data somewhere, when it returns to you, who knows what it’ll be.
Perhaps ‘(3 4 2 1).
With this in mind, do you really need setter methods?
From now on, I’ll try to make the data I use to be immutable when I can, of course sometimes there will be some trade offs.
2.Syntax isn’t everything.
When first starting programming, I believe that syntax was so important. What I now know is that concepts are more important. Of course during my time with clojure I’ve used what I’ve learned in other programming languages. What has really been difficult is functional concepts. I’m now more confident than ever that I can pick up another language because Clojure has pushed me. Some people may say clojure doesn’t have syntax. I think it does. Syntax is a set of rules and structures for a given language. Every language has syntax, simply put, Clojure has a ‘lack of’ syntax. But boy does it love parenthesis
3.Terse code can still be readable
Clojure code is small and terse but still readable, that’s if you have well defined functions and the number of lines doesn’t stretch to the 10s. And that’s what I like about Clojure, it guides me to write smaller functions because it becomes quite difficult to read once you have many parenthesis.
4. With lisp you only need a few concepts to build almost anything.
I was surprised that with “conj cons first rest” and few other functions you can accomplish quite a lot of useful things. I remember Daniel giving a Zagaku where he showed us how to build different types of functionality using Scheme.
This forced me to write simpler code. At times with languages like C#/Java I would write elaborate solutions because it allows me to.