How does Elm compare to ClojureScript?

回眸只為那壹抹淺笑 提交于 2019-12-31 10:59:12

问题


I'm reaching a point where GUI coding with Backbone.js object-oriented MVC pattern is getting quite complex, and looking around at other paradigms. MDV, FRP, ECS, oh my.

How does Elm compare to ClojureScript? Where do they overlap?

Both are languages very different from JS that compile to JS. I understand that Elm is a functional reactive programming (FRP) language. ClojureScript isn't necessarily FRP, but you can do FRP with it. Elm compiles with Haskell and ClojureScript with the JVM, so both of those are extra requirements for a Node shop.

Maybe it just boils down to Clojure vs Haskell.


回答1:


Both force you to use a more declarative/functional programming style than pure JS. ClojureScript is more like a JS replacement, whereas Elm is more like a replacement for the entire web development stack (HTML/CSS/JS).

Other differences:

  • Elm syntax is much more Haskell-like
  • ClojureScript is much closer to traditional Lisp syntax
  • Elm is highly optimized for time-varying values ("signals" in Elm)
  • ClojureScript is more mature and you can find some sweet development tools for it (Eclipse plug-ins, LightTable, etc.)
  • Elm is statically typed, ClojureScript is dynamically typed

Hope this helps. I'm still learning both of these languages so I may have missed something.




回答2:


Just to update this for 2017.

Elm is no longer FRP, that went away a few releases ago in favor of the Elm Architecture.

The major win of Elm is that it has a static type system that allows the compiler to make many assertions about program correctness at compile time. For example, you know for a fact that there will never be a time where a case statement does not cover a specific case. Or that the HTML from the view function will produce an event that the update does not know how to deal with.

Other Elm advantages

  • Great Error messages
  • Packages have enforced Semantic Versioning
  • Packages and tools tend to have really obvious names



回答3:


They are both FRP (Functional Reactive Programming) at their core - meaning they have a tree mapped out to the DOM and only render that component or children that need be rendered. (as someone pointed out earlier, Elm has abandoned the FRP principles to pursue its own idea of them)

They both compile in JavaScript (although with ClojureScript/Om library or Reagent you could get actual React objects in your js) while Elm does its own thing. I don't like that Elm has to be installed through npm although czapliki as I understand is working on a standalone installer)

Elm is nicer in my opinion because it manages state a little more coder friendly and it has a very nice (as was mentioned --) Haskell-like syntax and also you move the RuntimeErrors into the CompileTimeErrors which is much more agreeable as a developer - plus it has easier code maintainability.

On the other hand, cljs has lotsa libraries - some of them as I mentioned return actual React Components (cljs/Om matches 1:1 with R.js LifeCycle) - others simply respect the FRP and LifeCycle mentality without becoming encumbered by it. Might want to look into Om/Next with has a GraphQL way of calling for data from an endpoint and has dropped the async chans that were used in plain cljs/Om.

It's a matter of taste to be honest, but I for one would prefer Elm (having written in both languages). If you do however go with cljs make sure you get a nice library and don't do stuff in vanilla cljs or you'll be sorry when you want to maintain 5k+ LOC.(look up Fulcro, Reagent, om, OmNext, hoplon, etc.)



来源:https://stackoverflow.com/questions/18405158/how-does-elm-compare-to-clojurescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!