4 ms·
Once javascript gets immutable types and better handling of objects, the gap between it and clojure will very small for most daily tasks. https://github.com/tc
by Scarbutt 7y ago
Once javascript gets immutable types and better handling of objects, the gap between it and clojure will very small for most daily tasks.
https://github.com/tc39/proposal-record-tuple https://github.com/tc39/proposal-record-tuple
https://github.com/tc39/proposal-object-iteration https://github.com/tc39/proposal-object-iteration
- fnordsensei 7y agoIt’s not only about having immutable constructs available, but having immutability as default, and pervasive throughout the ecosystem.
- adamkl 7y agoThe issue that I find with JavaScript (which I use on a daily basis) is that it has become a "kitchen-sink" language. Every time it gets new additions to "close the gap" with some other language, it gains more ways to do the same things. A big thing with Clojure is that it tries to provide a single, idiomatic way of doing things (though overuse of macros may cloud this picture at times). Generally, you can hop into any Clojure codebase and very quickly understand what's what. Since JavaScript can do just about anything (functional, imperative, object-oriented, prototypical), there's no one "true" way of writing code, so while its possible use the "good parts" of JavaScript, everyone seems to have a different idea of what those are. Flexibility can be a virtue, but I find myself preferring Clojure due to the constraints it provides.
- hinkley 7y agoDoes anything illustrate this more clearly than the picture of 1e 'Javascript, the Good Parts' sat next to the O'Reilly Javascript book?
- zachrose 7y agoThat image was from a decade ago. The O'Reilly book must be three or four times thicker by now.
- kace91 7y agoAs you say, there is no objective "good parts" of js, what exists is basically a large language that can act as a framework for you to create a language you like by leaving only what you want in the subset allowed by your linters. That's arguably a lot of work, but the payoff is that you get to use your new hand tailored "language" anywhere js can run, which is not the case if you ignore js and just pick a language you like from the get go instead.
- adamkl 7y agoIf you are flying solo, then sure, I can see the appeal, but for most(?) of us, that hand-tailored language needs to be learned by everyone you work with, and anyone who might need to work on your codebase in the future. And it’s unlikely that those future coders will feel the same about your hand-tailored language as you do. (editing to mention the fact that Clojure targets both servers (via JVM/CLR) and browsers (via ClojureScript) so you lose none of the reach you mention with JavaScript)
- yogthos 7y agoThat is absolutely not the case. There's a huge difference between having immutable constructs available in a language and immutability being the default. Clojure is built around the idea of immutability from ground up. It makes it natural to work with immutable data, and it guides you towards doing the right thing. An example of this would be transients, which allow you to do local mutation within a function, but the compiler will give you an error if you try to leak mutable state. All of this greatly reduces mental overhead for the developer because vast majority of code is referentially transparent. You can reason about functions in isolation without having to know anything about the rest of the application. Meanwhile, simply bolting on immutable constructs on top of JavaScript puts the burden of using them correctly squarely on the developer. It's still perfectly possible to stick a mutable reference into your immutable record, and then pass it around and modify it. The language does nothing to help you there. Furthermore, you have to consider the culture and the ecosystem around the language. Pretty much all Js libraries are written in imperative style, and passing mutable data is the accepted practice. And immutability is just one aspect, there are plenty of other differences that are very important for many daily tasks. One major difference is that Clojure is a much smaller and consistent language. Clojure code tends to follow a few accepted patterns that the community settled on. Js is a giant language that's grown organically and acquired tons of quirks and gotchas over the years. It's a minefield compared to Clojure. Another day to day benefit of using Clojure is its tooling. You get reliable hot loading, which is pretty much impossible with Js, you have sane library management, minification, code pruning to function level, and code splitting out of the box. These features are especially important when shipping code across the network to the browser. You also get a REPL where you can connect your editor to your running application, and interact with it directly from there. Any time you write a function, you're able to run it immediately and see what it does. There's no waiting for your code to compile, or the page to reload, or having to rebuild the state. It's an incredibly tight feedback loop. In short, there's no comparison between ClojureScript and Js regardless of what constructs get bolted onto Js in the future.
- agumonkey 7y agothat's how I felt using immutable libs in python, it did help but the language still has open doors and I never really feel like juggling with potential side effect
- slifin 7y agoClojureScript is a superset of JavaScript, something as simple as writing a loop would very quickly illustrate there is a huge gap between the languages
- blueberrytea 7y agoHow so? Not disagreeing with the languages being different, but loops are very similar