4 ms·
I was referring to Clojure's immutable data structures, not immutability in general. My nodejs apps are just transformations pipelines of pure functions with po
by romero-jk 5y ago
I was referring to Clojure's immutable data structures, not immutability in general. My nodejs apps are just transformations pipelines of pure functions with postgres being my global mutable state. Clojure doesn't offer me anything here that I can't easily do with JS/node.
Sure Clojure is a better language but not better enough to justify the additional abstraction layer IMO.
- phyrex 5y agoIf you're using pure functions then you'd likely profit from clojure's data structures, as they're much cheaper to copy and modify than javascript's native structures. Of course you could use something like ImmutableJS or Immer, but then you're putting yourself at odds with the rest of the JS ecosystem and built-in functions and you have to transform values back and forth. This gets a lot easier with Clojure(script) (even though there's obviously still some casting back and forth when you're going outside the CLJs ecosystem)
- didibus 5y ago> Sure Clojure is a better language but not better enough to justify the additional abstraction layer IMO Speaks for yourself, I'd take a pay cut to be able to use Clojure over JS (don't tell anyone ) Some of the why that is is captured here: https://gist.github.com/didibus/6e5ff960b25fdc1a5f8f97acede614b0 https://gist.github.com/didibus/6e5ff960b25fdc1a5f8f97acede6... But understand that a lot of it is about what language you personally enjoy and prefer, Clojure makes programming 10x more fun for me, and I already am someone who finds programming in general fun.
- dkersten 5y agoI sorely miss Clojure's immutable data structures when I use other languages (Python, Javascript, C++). They give me a guarantee that nobody else is going to be changing the data, somewhere deep down the call stack. I've had cases in production Python code where some seemingly unrelated code module somewhere was mutating data without my knowledge, breaking whatever I was working on. This is much harder to have happen in Clojure (you have to go out of your way to store things in mutable types, or use Java interop hacks to do this, which shouldn't pass code review without good reason). Clojure's sequence abstraction also leads to a very rich and powerful set of core functions that make transforming your data a breeze. Other languages can do this too, but in Clojure I find its just really easy and natural since its part of the language's core library. It also helps emphasize pure functions: data in, data out. Which makes my code much nicer. Besides that, I use clojure because I like reitit and spec/malli for writing my HTTP routes, and hugsql for writing my SQL, both much better than the equivalent libraries in other languages I use. I also like its emphasis on data first, code second. Sure you can do this in other languages too, but Clojure encourages it since its something the community has rallied behind.
- deleted 5y ago[deleted]
- romero-jk 5y agoThey give me a guarantee that nobody else is going to be changing the data, somewhere deep down the call stack. I've had cases in production Python code where some seemingly unrelated code module somewhere was mutating data without my knowledge, breaking whatever I was working on. Since we are talking about single-threaded single stack context, immutability wouldn't have saved you here, even with immutability you could have receive the wrong value/data from some function in another module down the call stack. The problem was not mutation but a function returning bad output. You are implying some code modified data underneath you, which can't happen in a single thread.
- grzm 5y agoAn aspect of immutability I really appreciate is that I know no variable has been changed after it's been assigned to, including by me. If I want to know where the value was assigned, I only have to look for the only place it could have been assigned. I don't have to search anywhere else.
- romero-jk 5y ago99% of variables are local to your function, is not like program a thousand of global variables.
- grzm 5y agoSounds like you code pretty tight. I've seen plenty of functions reference variables out of function scope, or be reassigned within long function bodies. I personally don't code that way, but not everyone does. And as you've seen in this thread, there are people that do like immutability. To each his own.
- romero-jk 5y ago