6 months with Clojure

Divyum Rastogi
2 min readAug 19, 2017

--

I started with Clojure programming around 6 months back when I had no clue about what functional programming is. I am still a novice in clojure but would like to share my experience which people like me might face when starting with clojure or any other functional programming language.

The first impression of language

This is how to check if a string is plaindrome or not in clojure:

(defn isPalindrome? [s]
(= s (clojure.string/join "" (reverse s))))
=> (isPalindrome? "123")
false
=> (isPalindrome? "121")
true

When I first saw the code, it looked quite clean, simple and readable but thinking the functional way was going all over my head. Coming from a procedural programming (Python, Ruby, C++, ect..) background it is really very difficult to change your programming thought process and structuring the code but it is really important to think in a different way.

As a programmer, I look for simplicity of syntax and ease of coding in a language. Probably this is the reason why Python and Ruby has been adapted so quickly by the developers. Clojure does justice to some extent but when you start going deeper, you realise code is just the tip of iceberg and the base is functional thinking.

So clojure code is basically the outcome of your functional programming thought process. It looked simple but was weird and confusing while coding (because of my procedural thought-process).

Thinking the functional way

The best part I learnt is to think and see the solution in a functional way and when I started thinking that way, my clojure understanding improved to much extent. The complete code flows through functions. Functional code is characterised the absence of side effects. It doesn’t rely on data outside the current function, and it doesn’t change data that exists outside the current function.

Learning functional programming is like starting from scratch. So be patient and enjoy the process.

My first couple of months were really difficult adapting a completely new style of coding and thinking but eventually it matured. Some problems actually made me think how difficult and lengthy would it have been in case of procedural.

Functional thinking helps you to approach and solve problems differently.

Some key features of Clojure

Below are some features of clojure. I have not yet got my hands dirty on all of them but will soon explore.

  • Immutable
  • Software Transactional Memory (STM)
  • Lazy Sequence
  • Concurrency Support

Conclusion

Clojure is a good way to understand the ideology behind functional programming and to implement the approach in daily coding practice. It’s a good tool for concurrent and parallel programming because of its key features (yet to be explored).

The major improvement I see starting with clojure is building up the functional thought-process and trying to approach problems in a different way.

P.S. This article is just to express my experience while learning clojure and ideology behind functional programming. At the end of the day, language is just a tool to solve problems.

--

--