An Alternative to Elm - Part 2
Part 2 of 2: An Alternative to Elm.
If you missed Part 1: click here
So I went to look for an alternative that isn’t Javascript. There are 2 that probably piqued my interest. Purescript and Ocaml/ReasonML/Bucklescript.
Purescript, I just felt that over the last year, there hasn’t been much activity and it seems like they are just happy with it being hard for outsiders to learn. If you already know Haskell, it seems like a great choice, but maybe not for beginners. To be honest, I didn’t look too much into it and it just seemed just as “hard” as Haskell. It may be a viable option in the future.
Haskell itself seemed like something I want to learn in the future, but only for my curiosity. It seems like the language is more for researchers and less solid for production use. It has a lot of historical baggage, which Purescript apparently fixed a lot of, but still has many breaking changes with versions. It’s also kind of slow to compile. At least from what I hear.
You may want to do your own research on Purescript and Haskell as I really don’t much myself.
OCaml/ReasonML/Bucklescript - This is the option I chose for now and am learning about.
First off, I think when people see the OCaml/ReasonML/Bucklescript, they get intimated and confused. I know I did. So I want to explain what each is.
- OCaml, functional and typed language that’s been around for a while. Used by mostly financial companies like Jane Street.
- ReasonML is just another syntax for OCaml, that looks like Javascript. - Kind of like Elixir is another syntax for Erlang.
- Bucklescript is an OCaml to Javascript transpiler - meaning it takes OCaml and converts it into Javascript. Kind of like Elm does or Purescript does. Bucklescript creates readable Javascript.
- To use ReasonML for the web, it first converts to OCaml and then Bucklescript converts it into Javascript.
- ReasonML was created by Facebook, and is pretty popular right now. They have a web framework to go with it, called ReasonReact.
- Bucklescript was created by Bloomberg, but most people who use it are the ReasonML community.
- Bucklescript and ReasonML are not using the standard library ecosystem of OCaml (opam) and uses Node.js instead to better interface with Javascript ecosystem.
- An aside, there’s also js_of_ocaml library, part of the OCaml ecosystem, which does the same thing as Bucklescript does, but it isn’t human readable Javascript. Haven’t used it, but people say its even faster than Bucklescript.
- Bucklescript is also using an old version of OCaml whereas js_of_ocaml isn’t.
I chose OCaml over ReasonML though and here’s why:
- ReasonML looks like Javascript - I hate Javascript (even though modern Javascript is much nicer)
- ReasonML while fixes some of the legacy annoyances of OCaml, introduces other problems like with partial application.
- ReasonML already converts to OCaml first, if there isn’t really much benefit, why the bother?
- Although I do like and use Elixir over Erlang, that’s just because Elixir is so much nicer than Erlang when first introduced to the languages, plus I knew Ruby.
- There are downsides to this though. ReasonML is documented pretty well and has many more modern learning resources than OCaml when using with Bucklescript.
- There is a sizable community around Reason, not around OCaml when being used with Bucklescript.
- I get access to the stable OCaml community with all the libraries that it already has. I can use it for other things than just the web. I constantly hear people that only know Reason and get confused by all the existing resources for OCaml. I don’t like that.
- It looks like Elm, which I already know, and which I’ve grown to like the syntax.
Here’s why I chose Bucklescript:
It seems much more popular than js_of_ocaml. I didn’t want to lose all the advantage of the new community.
The documentation for Bucklescript is pretty good. Versus js_of_ocaml is just confusing when I visit their page.
Bucklescript-TEA library - An Elm architecture library written for Bucklescript. I explain the benefits more below.
I know, its weird the choices I made, it seems to contradict one another a bit, but its what I went with for now.
Here are the reasons why I’m choosing OCaml/Bucklescript-TEA over Elm:
- OCaml is stable, been around for 30 years. Changes are not that often, not breaking changes anyways. Bucklescript has been stuck on an older version though.
- OCaml is not developed by one person who is resistant to outside points of view.
- I can use OCaml for other than the web. It also has imperative language features to use when needed, but is somewhat clunky to use compared to other more modern imperative languages.
- Many existing libraries in the vast ecosystem for OCaml. Just that it won’t connect with Bucklescript.
- Bucklescript-TEA may use js_of_ocaml down the line.
- TEA - This one is pretty important. While I think React/Redux is not bad, TEA is superior in many ways.
- Javascript interop is much easier to use.
- Is more compact (vertically in a file) than Elm is, but its also much more verbose in many ways. Its more compact because the syntax is more flexible.
- If you add a flag, you can get really good messages like Elm.
- The maintainer of Bucklescript-TEA is friendly and open to requests and fixes.
- Bucklescript-TEA was originally written in OCaml and maintained by a primarily OCaml mindset. It has Reason syntax too (if you need).
- It compiles really fast, faster than Elm/Elixir and most other functional languages.
- It also really small already.
- The importing is simpler than Elm.
- More advanced languages features to reduce boilerplate (though I haven’t really gotten to this yet.)
Here are some downsides:
- OCaml docs are not great. The standard library documentation looks outdated and doesn’t have a search feature and nothing is collapsed. It’s all there, just needs modernization.
- Bucklescript-TEA itself doesn’t have docs, but its mostly similar to Elm’s API.
- Don’t know of a code formatter.
- Debugger is not that great compared to Elm’s time-traveling debugger.
- The language itself has legacy annoying things that just don’t lead to a clean experience. But its manageable. Syntax could be improved.
- No easy way for the Bucklescript and OCaml ecosystem to coexist together in projects. So all the new code being written in Reason and Bucklescript wont easily port to the OCaml system.
- Not that many modern learning resources for it.
- A fantastic REPL for just OCaml, but Bucklescript/TEA can’t use it. (Not that I know of)
Anyways, I think there are some great upsides to using OCaml with Bucklescript-TEA over Elm. It already includes most of the great features of Elm but with more. You should take a look if you are seeking an alternative to Elm or other Javascript web frameworks. I’m going to post more about it in the future. Thanks for reading all the way here if you actually finished this, both parts.