Background photo by Aaron Burden on Unsplash

A new language for the web

What is Reason?

A language from Facebook that compiles to JavaScript

Seth Corker
Oct 14, 2019 · 4 min read

Some sample Reason code

Why use Reason over TypeScript or Flow?

If you aren’t using a static type checker, I’m interested in why? Otherwise, if you’re already bought into the idea of static typing for JavaScript then you might wonder why you’d want to go through the process using another language entirely. Unlike TypeScript and Flow, Reason makes use of type inference so you rarely have to explicitly tell the compiler what the types are. It’s a frequent pain point I have with Flow and TypeScript on a daily basis that Reason solves. This saves a lot of time and effort compared with other static type checkers, Reason can infer the types and still give you the confidence you need.

But, Reason is compiled — won’t it be slow?

If you use tools like babel to transpile your source code to ES2015 today, you’re already performing something similar to compilation. It’s usually one of the many steps your source code goes through before reaching the end-user. If you’re not, then moving to a compiled language is a valid concern. To put your concerns at ease. Reason is very fast. I use a lot of tooling to create modern React applications including webpack, babel and flow. It can take a minute from a cold start and a few seconds whenever a change is made. It didn’t seem like that long but then I used Reason which builds in milliseconds. I wish all compiled languages were this fast, I’m amazed by the performance and it hasn’t posed a problem yet.

Debugging will be a nightmare right?

I use flow for static type checking on a daily basis and the tooling means that debugging is still very easy through modern devtools. Reason is no different, intermediary JavaScript files are created alongside your source by BuckleScript. The resulting code isn’t minified or obfuscated, in fact it looks pretty close to JavaScript code you might write yourself. The benefit of this is that you can follow what the compiler is doing and it acts a great mapping when debugging code.

Can I still use React with Reason?

ReasonReact is a library which allows you to use React in Reason. As far as other libraries are concerned, you can find Reason packages on NPM. Redex (Reason Package Index) exists to collate reason packages and make them easier to find. If the library you want isn’t there then the interop between Reason and JavaScript is relatively straightforward. The hardest thing you have to do is to write the binding between the package in JavaScript and Reason. It involves explicit typing to tell Reason what it’s working with and what types are expected. This can be challenging if the library you want uses a lot of dynamic types or is relatively undocumented.

Benevolent Bytes

Thoughts, stories and ideas about development. Web development and beyond.

Seth Corker

Written by

Sharing ideas, facts, and opinions about programming. 📚 Learn more React and JavaScript. 🗺 Learn web development tips and tricks 🛸 Discover something new

Benevolent Bytes

Thoughts, stories and ideas about development. Web development and beyond.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade