CLOJURE, A not so secret weapon
Clojure is not a new language anymore, it was created on 2007 by Rich Hickey, but I discovered in 2013 while I was searching alternatives to Java for a new project. Two things converged at that moment, the first one is that I was searching for a library, or a tool or language for coping with the concurrency in an easy and stable way, the second one, is that I was reading the book Hackers and Painters from Paul Graham where I ended up convinced to at least try Lisp in some way, and Clojure is a Lisp dialect.
I will not go into the details about specific aspects that I discovered in my first project with Clojure, instead, I will highlight the things that, to me, are the magic of Clojure. The most notable change for a developer that start coding in Clojure is the REPL (Read, Eval, Print Loop) way, the thing is that the interpreter is continually reading, compiling and executing code in a way that you never lose the state while you are changing the code. For ‘state’ I mean the data that your program reads, transform and finally build with specific logic (functions) with it, the state is the data structure that we, as programmers, use to model and solve real problems.
The ability to code incrementally, having the time to examine every data structure, every piece of function, being able to rehearse a small routine (a S-expression in LISP) to verify the result with the data you are seeing (your state); all these aspects constitute a huge shift in your paradigm. I felt that new ways of reasoning about my code were possible only using a RPEL style. It was a different feeling compared with my previous experience learning Python, although you can perceive the syntactical changes between languages, the core concepts remain essentially the same (as it happens between Javascript, C++, or Java), but with Clojure, it offers you a new way of thinking, because it certainly is, its name is Functional Programming.
Programming with functions is supposedly the foundation for Functional Programming, but the real benefit in Clojure, qualified as a functional language, is the presence of its immutable Data Structures. I was not aware of this during my OOP (Object Oriented Programming) years, but after read the paper “Out of the Tar Pit” I understood that a lot of the complexity (and bugs!) were hidden into the state, which for OOP disperse through objects.
In Clojure is possible to examine all the data because it is expressed with its own syntax (EDN: Extensible Data Notation ) in a transparent way, most of the time the programmer is encouraged by the language to develop in a way that is close to the data, avoiding to create additional layers on top the data, which by the way, tends to hide the very nature of the business logic. This aspect is so common that has its own name: Data Driven Development (DDD) :-).
It is not my purpose in this entry to explain the language, you can find a lot of resources for learning it in Internet (see the Links at the bottom), but let me just highlight the benefits in efficiency you can obtain if you create solutions using Clojure, I will dive into those benefits with concrete references to the source code and libraries I used to build Web applications in other posts.
REFERENCES
- Oficinal Web Site: http://clojure.org
- Online courses: https://purelyfunctional.tv/
- Youtube Channel: https://www.youtube.com/user/ClojureTV
Comments
Post a Comment