How I rediscovered my love for JavaScript after throwing 90% of it in the trash.
Joel Thoms
2.7K67

These sorts of “the biggest problem with language A is that it’s not language B” articles (yeah, it is) drive me nuts, especially as someone who has been programming for 40+ years, coming up through structured programming, OOP, and the current craze for functional programming. If language A isn’t language B, then just use language B! Surely if the biggest problem with a donkey is that it’s not a zebra, then you shouldn’t get a donkey. You should get a zebra. (Translated more directly: you and ClojureScript should just get a room. Nobody will judge you for it. If you can use Clojure itself, all the better, yes?)

I understand the concept of immutability for data which might be acted upon by multiple threads simultaneously (I’ve been writing C++ for decades) but my understanding is that JavaScript remains single-threaded for now, and workers are isolated from the main script and use copies of data, not the data. With no shared state possible, you needn’t worry about side effects from mutable data. You write the script that accepts function arguments and can ensure that passed objects aren’t mutated in any given execution context. It’s up to you to enforce the integrity of the data, and depending on JavaScript const isn’t the answer, because it only protects the name of the reference, not the data referenced. [In C++, const auto *p = result() protects the data behind the pointer, which is really want we want. JavaScript just gives you auto * const p = result(). Maybe that can be addressed in the future as a non-breaking change.] So the question becomes, what the hell are we trying to write that needs to worry so much about immutability? (Or are we just terrifically bad at programming?)

Lest you think I’m completely cranky and untenable: +1000 Internets for not using the phrase “reason about” in this article. The next person that uses that phrase around me is going to get “3.1415926” scrawled on his or her forehead in permanent marker. Yes: a π in the face.

Show your support

Clapping shows how much you appreciated Brook Monroe’s story.