←back to thread

498 points azhenley | 1 comments | | HN request time: 0.207s | source
Show context
EastLondonCoder ◴[] No.45770007[source]
After a 2 year Clojure stint I find it very hard to explain the clarity that comes with immutability for programmers used to trigger effects with a mutation.

I think it may be one of those things you have to see in order to understand.

replies(17): >>45770035 #>>45770426 #>>45770485 #>>45770884 #>>45770924 #>>45771438 #>>45771558 #>>45771722 #>>45772048 #>>45772446 #>>45773479 #>>45775905 #>>45777189 #>>45779458 #>>45780612 #>>45780778 #>>45781186 #
ndr ◴[] No.45771558[source]
Clojure also makes it very easy, it'd require too much discipline to do such a thing in Python. Even Carmack, who I think still does python mostly by himself instead of a team, is having issues there.
replies(1): >>45774914 #
MetaWhirledPeas ◴[] No.45774914[source]
> it'd require too much discipline to do such a thing in Python

Is Python that different from JavaScript? Because it's easy in JavaScript. Just stop typing var and let, and start typing const. When that causes a problem, figure out how to deal with it. If all else fails: "Dear AI, how can I do this thing while continuing to use const? I can't figure it out."

replies(3): >>45775194 #>>45780834 #>>45781656 #
1. filoeleven ◴[] No.45781656[source]
Javascript only enforces reassignments to const. So this,

  const arr = []
  arr.push(“grape nuts”]
is just peachy in JS and requires the programmer to avoid using it.

More importantly, because working immutably in JS is not enforced, trying to use it consistently either limits which libraries you can use and/or requires you to wrap them to isolate their side effects. ImmerJS can help a lot here, since immutability is its whole jam. I’d rather work in a language where I get these basic benefits by default, though.