5 ms·
I've been really thinking about using a functional language that complies to JS to start to learn more FP concepts and paradigms. I'm trying to decide if Clojur
by rhlsthrm 6y ago
I've been really thinking about using a functional language that complies to JS to start to learn more FP concepts and paradigms. I'm trying to decide if ClojureScript or ReasonML is better for me. Anyone have experience with both?
- enricozb 6y agoBoth are beautiful in their own ways. I think ReasonML, or even SML or OCaml might be a gentler introduction since they let you write imperative code (more closely to what you probably write already) whenever you need to. For example, I think there is a gradient from OCaml > Clojure > Haskell about using mutable data structures in your code, from Encourage > Discourage > Disallow. I think learning Haskell as your first FP might turn you off given how strict it is in this regard. So using that as a line of reasoning, using OCaml or ReasonML might be best since it lends an imperative hand whenever you need it, and lets you explore all of the amazing things FP has to offer.
- yomly 6y agoAs a counterpoint, Clojure is considerably more permissive because it is dynamically typed: CLJS has some warts due to the compiled JS being hard to understand (use source-maps) and the Clojure error messages being bad is now a meme but if you've not dealt with a Hindley Milner type system before, Clojure can help you learn some of the other basic FP concepts in a more gentle way. I think it comes down to what you want to learn from FP and where you're coming from: If you want to just "build stuff" and make it "more functional" ie using lots of data/values and passing around functions maybe go with Clojure. If you're interested in how static types can make things easier to build more robust things but you only want to dip your toes into FP go with OCaml/Reason If you want to see what it means to program 100% pure and have no side-effects (and you're willing to invest in learning and delaying instantly "shipping" something) go with Haskell/Purescript
- deleted 6y ago[deleted]
- draven 6y agoI wouldn't say Ocaml encourages using mutable data structures. You have to use a ref to have a mutable variable. Most stdlib data structure are not mutable (operations on them return an updated structure.) Perhaps Common Lisp is a better example of a language in that part of the functional purity spectrum ?
- christophilus 6y agoI don’t know. Having used both, JS to CLJS was a much easier transition for me than JS to Reason. CLJS makes mutation pretty trivial if the thing you’re operating on is a JS object.
- fulafel 6y agoThere are built in mutable data structures now too: https://clojuredocs.org/clojure.core/transient https://clojuredocs.org/clojure.core/transient Though their usage in public interfaces is not idiomatic Clojure and they come closely coupled with functions to transform them back to immutable values. You can look up eg TransientArrayMap in ClojureScript internals to see how it's implemented on that side: https://github.com/clojure/clojurescript/blob/799d62fe3bba999287558538ca6b61501de02d49/src/main/cljs/cljs/core.cljs#L7052 https://github.com/clojure/clojurescript/blob/799d62fe3bba99...
- billfruit 6y agoPerhaps PureScript as well.
- dgb23 6y agoI can only speak about clojure. It is a very simple, very well designed language. I don’t know ReasonML specifically but one core difference to typed FP languages is that Clojure is less obstructive generally speaking.