Facebook published Reason a few days ago and after the initial surprise and thinking “hey, this will be good” I am a bit disappointed. I am aware that this is a preview and changes are to come, so this blog post is to give my initial impressions, coming from a person already using OCaml on and off since a few years.
OCaml syntax warts
When I heard that they changed the syntax I was quite happy, because the OCaml syntax can be quite whacko, I have a number of complaints:
begin
/end
are horrible delimiters and make code look ugly- I can never remember where to put the type params
- Constructors can’t be used as functions (unlike its predecessor Caml Light)
;
in lists is weird- Nested pattern matching needs params unless it is the last branch of a match
let-in
seems overly verbose- The precedence of
::
can be surprising ,
vs*
in tuple types- (I also hate typing
;;
in the Toplevel, but that seems fixable)
This might seem nitpicky, but when switching between OCaml and other languages, I do trip over these things every now and then. But with some thought it is possible to write beautiful programs in OCaml, as notty demonstrates.
Reason syntax
Now contrast Reason to OCaml:
- Instead of annoying
;;
you get an annoying;
in the Toplevel. 50% better, but not yet a complete win - Operator renaming. No idea why they got renamed. They all seem more verbose
and I can’t imagine any JavaScript programmer saying “I’d love to see
===
in other languages”. No big deal in any case. - Local scope: Can’t remember when I needed this in languages other than Rust,
though the addition of
{}
gives it an C-ish vibe which I don’t particularly enjoy. And the;
in the end seems like noise. Remember Pascal where there wasend
as well asend.
? No? Nobody misses it. - Tuples have changed, but I don’t have strong feelings about them, but I kinda
dislike using
:
for assignment in Records. OCaml uses:
for type annotations, which is a habit other languages have picked up as well. In Reason it means a numer of things now, depending on the context - Tuple arguments in constructors was very annoying in OCaml, so that is better now
- Why change
match
toswitch
? It’s aRustismSwiftism and the necessary angle brackets make it look verbose. I agree that nested matches are inelegant in OCaml, but this can be fixed by wrapping in()
which even makes sense logically, since()
are just precedence operators and what we are doing is literally changing the precedence. Update: Rust usesmatch
as well. I don’t enjoy the extra(Fixed quicky after mentioning on;
in some OCaml examples making OCaml look more verbose than necessary.#ocaml
, nice)- I just hate the
;
in Reason. It doesn’t make any sense, unlike in OCaml where it can be seen as sequencing operator of roughly() -> 'a -> 'a
type. The semicolon to terminatelet …;
makes this really weird, so;
is even worse than the already unwieldylet … in
.
So overall it did some things I disliked for the better, some markedly worse
with a dash of changes for changes sake. The question is whether it is possible
to write elegant code in Reason and the introduction of {}
in all kinds of
places makes for a more noisy syntax. These changes, though there are some
positive ones, don’t quite balance out the noise, so for me OCaml still reads
nicer.
Missing things
Some things that are not yet addressed to Facebooks “new developer experience for rapidly building fast, safe systems”, yet are important:
- Stdlib. Will every Reason program build its own extended standard library? Will everybody use Core in lack of good alternatives? OCaml is in a bit of a Catch-22 with libraries not wanting to include a heavyweight dependency like Core, which due to its size is unwieldy. For applications it doesn’t matter much.
- Concurrency. We have Lwt and Async (on life-support) with a near-future OCaml bringing an effect system. Would be interested to hear what Reason’s plans in this regard are. I suppose it’s worth waiting for how OCaml will develop.
- Documentation. A book for beginners (hopefully as good as RWO), some best
practices, tutorials, a community to group around? So far I heard there
is
#reasonml
on freenode, but I have doubts that this will be enough if Reason grows.
The good things
After this complaining what I didn’t like, I did enjoy some things:
- Interop with OCaml. If it uses the same compiler backend and has the same type system, mixing with OCaml is possible. So Reason can use OCaml code without caveats as well as OCaml can interact with Reason code without issues. So it doesn’t matter what adoption Reason gets or does not get, the OCaml ecosystem wins.
- Focus on good tooling. OPAM, Merlin and to a lesser degree utop made working with OCaml a lot better, it is great to see that Reason supports OTOP, Merlin and rtop out of the box. Having some editor integration that just works would be nice as well as a canonical build system which covers the 80% case well would be a great sell. Everything working out of the box without strange caveats could be a game-changer.
- Huge audience. Facebook Jordan Walke have gotten a lot of well deserved developer goodwill by creating React and also some recognition in the OCaml world for creating Infer, Pfft, Flow. Putting the ideas of OCaml and even OCaml itself in front of a huge audience of developers could be potentially huge.
So overall: not a language for me (yet?), but I am cautionously optimistic that through some iterations we might arrive at something reasonable.