Hot Take From A New OCaml Developer

I recently started a new job at Arena.io. One of many things that attracted me to the role was that they proudly use OCaml. Even if you’re a professional developer, you might not know of it. It’s not a widely used programming language, but it has been highly influential on many of the most cutting edge programming languages. If you’re not an OCaml, suffice it to say, this post probably won’t be that interesting to you.

You’re still with me, so I guess you’re at least familiar enough with the OCaml to hear me out. So here’s the hot take I promised: OCaml’s future is Reason.

Alright, caveats:

I’m really new to the OCaml scene, so I must humbly admit that there’s a whole lot of context and history I don’t know. There’s a lot about the basic language I don’t know. So maybe I’m way off base. Or, maybe, my outsider perspective gives me some objectivity that an insider might not have. A little of both, perhaps. Oh well, I’m sure I’ll learn from the feedback.

What is Reason?

From what I’m reading, most people think of Reason as a compile-to-JavaScript language. Which it is. But in learning about it, I’ve come to understand that the compilation to JS part existed before the invention of Reason, in the form of BuckleScript. Reason is just an alternative OCaml syntax and still uses the BuckleScript compiler under the hood.

So, it’s kind of like CoffeeScript, in terms of being a language designed to make another language a little more friendly to work with. But Reason just is a 1:1 mapping to standard OCaml, whereas CoffeeScript introduced features that mapped in nontrivial ways to JS. So that actually makes Reason less ambitious in scope than CoffeeScript.

The reception of Reason

It has been interesting to observe the reception of Reason. Before starting my OCaml journey, I was already aware of the buzz around Reason from dev friends and people on message boards. People seemed impressed by the fact that Facebook is using it as their preferred language for making React applications. Some of these folks are frustrated JS’s poor support for immutable programming and TypeScript’s lack of soundness. Others are intrigued by a smoother onramp into learning a language they had maybe been a bit intimidated to learn.

Now that I’m trying to assimilate into the OCaml community, I notice a contrast in how Reason is viewed by OCaml veterans. On one hand, some are excited about the buzz it has created in a community that is otherwise a bit niche. But on the more pessimistic side, others are suspicious about the concept of making OCaml more “like JavaScript”. I suspect that dissonance comes from the fact that OCaml is a very principled and tidy language, while JavaScript is…not.

Why I’m sold on Reason

In learning OCaml, it’s plain to see the  influence it has had on other languages I’ve spent more time using, like Scala and also the radical changes that ES6 brought to JavaScript. Those changes were highly controversial a few years ago, but at this point, everyone writes far more terse JS code, with heavy reliance on object and array unpacking and splats. This feels really similar to OCaml’s pattern matching. So one has to recognize that if Reason makes OCaml more like JavaScript, that’s a JavaScript that has already become more like OCaml.

Then I read Reason’s own comparison with OCaml, and that clinched it for me. It occurred to me that while the syntax looks superficially JavaScriptish, what it really seems to be about is addressing some of the warts of OCaml’s syntax. Syntax is largely subjective. But I think it’s uncontroversial to say that every language grows usages and features that don’t play well with preexisting syntax. Over time, this problem gets worse. JavaScript is Exhibit A of a language loaded down with regrettable early design decisions. ES6 was an attempt to smooth this over a bit, but there were limits to what it could do.

That brings me to my thesis. Reason seems to me to be an attempt to rethink all the regrettable syntax design decisions of OCaml and apply the positive aesthetic aspects of newer languages. From that perspective, it’s a huge win. Most languages–including JavaScript–would love to be able to pull off a trick like this. So what are we waiting? Let’s make the switch!

One thought on “Hot Take From A New OCaml Developer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s