6 ms·
A bit of an obvious question Elm, Typescript and Purescript all offer Javascript + Types Clojurescript is dynamic, beside the lisp syntax which is arguably cle
by systems 6y ago
A bit of an obvious question
Elm, Typescript and Purescript all offer Javascript + Types
Clojurescript is dynamic, beside the lisp syntax which is arguably cleaner, and offer some nice advantages like homoiconicity
What is the real advantage of Clojurescript (?)
- shaunxcode 6y agoto name a few: immutable data structures out of the box (with literal syntax), macros, being able to share code with the back end (cljc).
- cliftonk 6y agoCan share much of the same code on front end / backend. Excellent built-in immutable data structures. Arguably the best modern lisp. Community is usually ahead of its time on state management solutions. Typescript is probably a better fit for most people doing most things.
- divs1210 6y agoFor me, the primary advantage has been the ecosystem. Reagent and re-frame have been awesome since Day 1, even as react has tried to play catch-up with hooks etc.
- napsterbr 6y agoVery interesting take from re-frame's author regarding React Hooks (and why it ultimately doesn't matter that hook-based components are not very popular on CLJS): https://github.com/day8/re-frame/issues/590#issuecomment-624485714 https://github.com/day8/re-frame/issues/590#issuecomment-624...
- fiddlerwoaroof 6y agoI’ve been writing a lot of react over the past several years (JS/TS), and I strongly agree with this take: hooks, especially hooks like useState really are an attractive nuisance that, by making it easy to have local state in components, end up spreading business logic all over the view layer and coupling all the wrong things together.
- raspasov 6y agoAgreed. I would not use local state apart from fine-grained performance optimizations or temporary, always-can-be-thrown-away state specific to the component itself. Example: email field input before passing validation.
- fiddlerwoaroof 6y agoI’ve had the experience, though, that “temporary” state often becomes a feature requirement. Like, you have a field to search your dataset by email address and, next iteration, the product manager wants autocomplete based on partial input.
- raspasov 6y agoThe autocomplete results can come from the global app state. There’s no rules written in stone about what should be in local state. My default is “as little as possible”.
- fiddlerwoaroof 6y agoMy point is that I’ve found that there is very little local state that doesn’t eventually benefit from being merged into the global state management store.
- raspasov 6y agoFair enough.
- slifin 6y agoOne of the underated aspects is the inbuilt Google closure library https://developers.google.com/closure/library https://developers.google.com/closure/library So nice to have a good standard library when using JavaScript My favourite "type checker" is clj-kondo
- pizzeriafrida 6y agoYea it's funny how much is in there, between it and the Clojure standard library you basically don't need to go searching for third party libraries. I needed a debounce the other which was just importing `[goog.functions :refer [debounce]]`
- pizzeriafrida 6y agoThe question is funny because on the the list of advantages that Clojurescript offers the syntax / language is quite low on the list imo. Clojurescript has the best client-side build tool I have used in https://shadow-cljs.github.io/docs/UsersGuide.html https://shadow-cljs.github.io/docs/UsersGuide.html and everyone uses it. Clojurescript targets/outputs Google Closure compatible code which is easily the most sophisticated JS compiler out there. The reason no one uses it is because writing compatible code by hand is a nightmare. Clojurescript's front end libraries are incredible, they are basically a better expression of Redux because the Clojure language has constructs that enable a more expressive API https://day8.github.io/re-frame/re-frame/ https://day8.github.io/re-frame/re-frame/ Clojurescript's JS interop is actually insane, boosted by the quality of Shadow-cljs. You can write 1:1 javascript in clojurescript if you need to. A trite example would be npm installing lodash and writing some code that uses it, I have done this and it just works. Clojurescript's developer experience with the browser repl is next level. I know a lot of the stuff I'm saying sounds hyperbolic, but I've written a ton of Javascript and react and I really like it still, but using a browser repl to manipulate application state in my editor and reload functions without a full refresh is great. And I guess lastly, yea the language is awesome. It's basically my perfect version of Javascript. No need to fumble with libraries like immutable.js, no need for additional libraries like ramda or lodash because the standard clojurescript library has everything+.
- adamkl 6y ago“It's basically my perfect version of Javascript. No need to fumble with libraries like immutable.js, no need for additional libraries like ramda or lodash because the standard clojurescript library has everything+.” This pretty much my view as well. There’s that classic joke comparing two books on JavaScript, the complete language vs. the good parts [0], and you could pretty much just replace the “good parts” book with ClojureScript. It has everything you need and gets rid of most of the stuff that enables people to write bad code. (Assuming you like functional programming, of course) [0] https://i.redd.it/h7nt4keyd7oy.jpg https://i.redd.it/h7nt4keyd7oy.jpg
- chrisjc 6y agoSorry for what might be an obvious answer, but when you say >because the standard clojurescript library has everything+ do you mean bc it has all those libraries incorporated, or bc it's able to emit the equivalent to native javascript?
- ebruchez 6y agoYou forget Scala with Scala.js, which is fantastic. https://www.scala-js.org/ https://www.scala-js.org/
- Scarbutt 6y agoThe benefits of using Clojurescript over JS/TS in 2021 are superficial and not worth it IMO. Typescript is great, has good tooling and plays nice with the JS ecosystem. With Clojurescript you spent more time fighting integration with the JS ecosystem than getting any real work done. The mismatch between JS objects and Clojurescript data structures is annoying and tedious and riddle with performance issues, and Clojurescript in general has many performance issues.
- brokenkebab 6y agoChoice of abstractions which suit your thinking is obviously subjective so some people naturally prefer TS or Scala.js or PureScript over Clojurescript, (or whatever else over Clojurescript). However, the statement "you spent more time fighting integration with the JS ecosystem" is evidently not true. In my own experience you can do almost everything never leaving CJS realm, and when you need to combine it with existing JS code it will require some deeper understanding, but nevertheless goes pretty easy. Didn't downvote you btw
- raspasov 6y agoI usually avoid a direct ad-hominem attack but here I think I have to. Most things this person says in every thread about Clojure are false.
- lukashrb 6y agoCould you give us more details about the problems you running in?
- djblue 6y agoFor me the real advantage is the shared information model with the backend that is trivial to serialize/de-serialize with something like transit-clj(s). It's like the benefit of js/node but with richer data structures: keywords, symbols, sets, maps with arbitrary keys, instants, uuids and extensibility via tagging. JSON is great, but EDN is so much better!
- achikin 6y agoIt offers REPL, great hot reloading, a small set of immutable data structures, and a great set of carefully architectured core library functions to work with those data structures. Also because of immutable data structures it has a very clean comparison semantics e.g. you can compare data structures by value with `=` which helps a lot in React-like environments. The absence of static typing enables you to write more general code with less effort. All that leads to simple, clean and compact code. If you check Real World App statistics [1] you'll see that Clojurescript/Re-frame implementation has the fewest LOC (almost 4x less than Elm and 3x less than Purescript). [1] https://www.freecodecamp.org/news/a-realworld-comparison-of-front-end-frameworks-with-benchmarks-2019-update-4be0d3c78075/ https://www.freecodecamp.org/news/a-realworld-comparison-of-...
- iLemming 6y ago> What is the real advantage of Clojurescript IMO. Interactive development. It allows you to connect to a running program (local or remote) and tweak things on the fly. Without even affecting the state of the program. Without even having to save or re-compile. It's hard to explain the benefits of that approach. One has to experience it. Another major benefit: true code re-use. You can write functions that would work both in Clojure and Clojurescript (even though we're talking about very different environments). With Javascript/Typescript (in practice) that is hard to achieve even when you have a nodejs backend.