5 ms·
Thanks for the long post and sharing your experiences. I learned from you that Clojure is appealing for folks coming from Java. I read your conclusions and jus
by tferris 15y ago
Thanks for the long post and sharing your experiences.
I learned from you that Clojure is appealing for folks coming from Java. I read your conclusions and just got a vague feeling only. Coming from other worlds (like node/js, Haskell, ocaml, Go, Erlang and for the sake of completeness Ruby/Python, C++), I'd like to know good reasons why one should try Clojure from your point of view? What is the main USP to dive into Clojure (except the similarity to LISP)?
I just checked Wikipedia sayings things like 'treats code as data and has a sophisticated macro system' or 'concurrent programming through software transactional memory, an agent system, and a dynamic var system'—but I'd be happy to get more explanations/reasoning on this and why Clojure is so special compared to other languages.
- weavejester 15y agoIt really depends which "world" you're coming from. Someone coming from Ruby might benefit from the immutable data structures, but someone coming from Haskell would take such things for granted.
- tferris 15y agoThanks, then I'd opt for a comparison to nodejs if you don't mind. EDIT: Sorry that I was unclear, I meant obviously JavaScript, in particular server-side JavaScript, e.g. Node.JS
- deleted 15y ago[deleted]
- eaurouge 15y agoNode.js is not a language.
- weavejester 15y agoIn my opinion, I'd say the main difference is that Clojure tends to be a box of many tools that have very specific functionality, while Javascript tends to have fewer tools with very generic functionality. For instance, in Javascript an object is a way of storing values, defining an identity (i.e. a mutable pointer to a value), namespacing, polymorphism and inheritance. In Clojure, each piece of functionality is handled by a different tool. If you just want a value you can use an immutable map. If you want a changeable identity you might use an atom. Polymorphism is provided by protocols or multimethods, namespacing by namespaces and so forth. The advantage of using discrete tools is that you can afford to specialise. Clojure has atoms, refs and agents for maintaining identity, and each has unique properties. Libraries (such as Avout) can extend this with their own systems for maintaining identity. Javascript, along with many OOP languages, has the problem that objects are a jack of all trades, but a master of none. An object cannot handle atomic state change as well as an atom, nor handle polymorphism as well as a protocol, nor is it a good at namespacing as a Clojure namespace. By being so general-use, it can't be as good as tools that focus on doing one job.
- irahul 15y ago> What is the main USP to dive into Clojure (except the similarity to LISP)? 1. Runs on JVM. JVM is good for long running and/or compute intensive processes, has extensive ecosystem and enterprises dig it. 2. STM and immutability makes reasoning about concurrent programs simpler. Concurrent programs are needed for a lot of problems, and are difficult to get right. 3. The seq abstractions are good. If you program idiomatic clojure, your program is as concise as your ruby code. 4. It doesn't support conventional OOP, but allows inter-operability with Java and class generation. When you are programming clojure, you use records and types which are Clojure's way of doing OOP. All that said, look at a couple of programs written in Clojure, and try translating it to the language you are familiar with. That will be the best estimate of what Clojure is good for.
- tferris 15y agoSo, 1 and 4 are beneficial for people coming from Java. Could you give more info on 2 and 3 in comparison to node for example? > try translating it to the language you are familiar with. That will be the best estimate of what Clojure is good for. That's the point, even if I follow your advice: I don't have any clue why I should try Closure, me not coming from Java it doesn't appeal at all. I am aware that Clojure seems to be the new kid on the block many are talking about and therefore I am asking (to just get it). My feeling is that Clojure's USP is the mentioned features combined with the closeness to Java and the JVM—so is it right to assume that it's basically the new kid on the block primarily for Java devs who like to get some fresh air without moving to far away from their ecosystem?
- swannodette 15y agoClojure also targets JavaScript via ClojureScript. So you could write Node.js apps with ClojureScript as well.
- Kototama 15y agoFor me Clojure is the best Lisp available, JVM platform or not. It's more functional than the other Lisp, use immutable data-structures, have a lot of data types (vector, set, map, list) with literal syntax and unified abstraction on top of them and the macros are easier to write than in the other Lisp thanks to autogensym and name capturing. Main selling point: it's Lisp and it's the best available.
- samdk 15y agoOther people's attempts to answer your question seem to have not done what you're looking for, so I'm going to try to be more specific. First and foremost, Clojure is a Lisp. Many other people more qualified to describe the benefits of Lisps have done so, so if you're looking to be convinced about why that aspect of the language is valuable, go and read what they've written. Looking at Clojure and ignoring the Lisp-related arguments is a bit silly. It's dynamically typed, which sets it apart from the ML family of languages (SML, OCaml, Haskell, F#, etc). It has immutable data structures, which sets it apart from some of the elements of ML-like languages. It's eager, which sets it apart from Haskell (although Tyr42 rightly points out that many of its sequence operations are lazy). It has good support for multi-processor concurrency, unlike OCaml, because it has STM, and so doesn't have the problem of a global lock. It's functional, and its primary programming style is functional, and it has immutable data structures, which sets it apart from Ruby, Python, Go, and to some extent JS. It's higher-level than Go/C++/C. It doesn't rely on callbacks for absolutely everything, like JS does. It's not object-oriented, which sets it apart from Ruby/Python/JS. It's a new language, which means it doesn't have the many accumulated years of cruft that Ruby/Python have, and it's well-designed, which means it doesn't have the many, many problems JS has as a language. It has multi-processor concurrency support that Ruby/Python/JS don't have. Compared to other Lisps, it's a very practical language. It has native syntax support for vectors and hash tables. It's built on the JVM, which gives access to a lot of existing tools and libraries.
- tferris 15y agoGreat post, thanks! First answer that gave me some motivation to look more into Clojure.
- Tyr42 15y agoWell, most of it's sequences are lazy. map, take, ect are all lazy. Which is awesome because they are composable (at least, to me, coming from a Haskell background).
- sandGorgon 15y agoclojure has a nicer community as compared to other lisps (c.l.l was notorious). That is a major advantage. clojure's package manager (lein/cake) is as good as bundler+gems which is a big advantage over similar languages. However, the packaging itself is closely tied in to java/maven way of working - which I personally things needs to go away.
- technomancy 15y agoClojure's approach to state is often cited as being great for concurrency, but it really simplifies things across the board. Old hat for those coming from an ML background, but for most this is a huge benefit vs traditional OO: http://clojure.org/state http://clojure.org/state
- calebmpeterson 15y agoAgreed; this was the most revolutionary idea for me when learning Clojure (coming from a classic C/C++/Java background). Clojure's approach to state is so good/different that it has completely changed the way I write code. It was a huge paradigm shift for me.
- djpowell 15y agoLet's say you have some data, perhaps some of it is from an SQL database, some from files, some from NoSQL. In Clojure there is a small set of data structures, and a unified lazy sequence abstraction that can bring all of these together. You've got a huge standard library of functions for manipulating sequences and maps, rather than having to write your own one-off functions for working with custom OO classes. Perhaps you want to do some processing on the data and convert it to JSON. Immutability and lazy sequences let you work from the problem towards the solution by layering small reusable functions over your data to get it to where you want it. And you can do this without it being hopelessly inefficient. Another advantage that is easy to overlook is the environment. The ideal Clojure environment is an editor or IDE that is backed with a REPL. You can write a bit of code in your editor, perhaps assign some test data to a variable, and then with a couple of keystrokes, send the code to the REPL and see it working in a live environment. Perhaps your function isn't quite right, no problem, fix it, a couple more key-strokes and try it again. Writing code incrementally in this way has a similar effect to test-driven development. You are writing small pieces of code and the code is being tested as you develop it (albeit only informally).
- th0ma5 15y agoJust as an FYI there is some work to implement a Lisp with the Clojure dialect for Python and the standard library: https://github.com/halgari/clojure-py https://github.com/halgari/clojure-py
- rlander 15y agoI started using Clojure roughly around the same time as the OP and have mostly abandoned Python as my general programming language in favor of Clojure. Here's why: 1. Simplicity. No more thinking about objects and their weird/complex interactions. Although even in Python I was used to writing functions instead of classes, every once in a while I was forced to think about classes. I think objects are the wrong kind of abstraction for 99% of what I do. In clojure you just define a map and write functions that operate on it. 2. Incremental development. Yes, you can somewhat do that in iPython, but it's limited. In Clojure, I can start development at the repl, move code to the file/namespace when it is good enough, run the program, go back to the repl and insert myself into that namespace and modify live code, on the fly. 3. Immutability. I was already sold on immutability from Erlang. 4. Functional programming. Same as above. 5. One language, multiple runtimes. Clojure was designed to be a hosted language. This means it is not endemic to the JVM as noted elsewhere in this thread. You can already use clojure to target the JVM, CLR, Javascript and Python. No more encode/decoce Json/Xml/Yaml whatever between runtimes. Now, one of the reasons it took me so long to "discover" clojure is the JVM. Most books assume you are a Java programmer and are familiar with Java and the JVM, which was not my case at all. In fact, besides not knowing anything about the JVM, I also hated Java the language. But you eventually learn to like the JVM and everything that comes with it.
- tferris 15y agoThanks. Gave me a much better understanding. Now, I want to try it. How does Clojure compare to ClojureScript?
- spacemanaki 15y agoIf you're starting out, I would recommend Clojure first. ClojureScript is basically the same language, although there are large pieces missing (since JS is single-threaded the only managed reference supported is atom, there is less support for runtime reflection like docstrings and exploring namespaces dynamically) but right now things are a bit rough around the edges, although they are getting better rapidly (see: ClojureScript One). It's just that when you get stuck with some issue with ClojureScript (like a browser connected REPL barfing on you or debugging the JS that comes out of the ClojureScript/Google Closure compiler, or understanding how macros work) I think it really helps to have a solid grasp of Clojure. See this for more details, although it might not mean much to someone new to Clojure: https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure https://github.com/clojure/clojurescript/wiki/Differences-fr... That being said, if you have some desire to experiment with alternatives to JS in the environments that is has traditionally been the only choice, ClojureScript is a compelling alternative, and ClojureScript One is an absolutely fantastic place to start. I have really enjoyed working with it and with ClojureScript in general, and huge props are deserved to those making it a better experience, because it's come a long way very fast.