|
I'm trying to learn Clojure at the moment at the recommendation of Paul Graham and other technologists whom I greatly respect. But as I work through various coding challenges in an attempt to come to grips with the language, I have yet to encounter a single problem that is solved more elegantly in Clojure than the equivalent Pythonic solution. I am really trying to have an open mind, but I don't want to join a cult, either. It really feels at this point like Python has subsumed the best features of every dynamically typed language. Typically, people endorse Clojure for the following reasons:
1. It's functional!
OK, well, all the higher order functions exist in Python, too, but in fact you wouldn't want to use them anyway because in Python you have list comprehensions, which, it turns out, usually leads to an even more readable solution.
2. REPL-driven development!
Python also has a REPL. True, it isn't the best REPL imaginable, but as far as I can tell it has feature parity with Clojure's! Both are missing the ability to fix errors live in a breakout REPL like you would find in a true LISP REPL.
3. Macros! Code is data! You can easily create your own DSL!
OK, maybe. But actually, in Clojure I've gathered the impression that macros are looked down upon, a feature of last resort, unlike in other LISPs. I also can't recall ever using Python and wishing I could replace its syntax with a DSL, since it is already so expressive and flexible. But admittedly that might be a limitation with my own imagination and experience. People tend to say all these things in favor of Clojure, but when you actually investigate them they seem quite flimsy. Meanwhile, for a language like Python the value product is clear and obvious. Where else are you going to do your machine learning, for example? I really am not trying to be an asshole to people who do enjoy and like Clojure, because I want to be one of you! I just need some reason to continue learning because clearly I haven't yet grokked the benefits. If anybody could concisely explain the advantages Clojure has over a language like Python (speed, maybe?) which do not fall apart under close scrutiny I would be grateful. |
2. The REPL is not on par. You can run an in-editor REPL and build your entire program in a REPL session. Combined with tap you can visualize your output on the fly.
3. Macros are used, not looked down upon. But they are discouraged when not needed. Much of the power and succinctness of the language comes from macros. Boilerplate is a solved problem.
There are a lot of subtle and less obvious advantages too, like namespaced keywords, a highly productive and creative niche community, a very composable and simple library ecosystem and a huge emphasis on stability.
But disadvantages exist too. The Clojure toolchain has a nice surface but is more involved under the hood. There’s also not a single happy path framework for the web, but rather a variety of library options. Finally, Clojure isn’t the best fit for certain types of programs, it’s really optimized for applications and data centric stuff.