ReasonML: what you need to know

Reasonml article by hackajob

Reasonml is one of the most controversial hashtags on Twitter. Love it or loathe it, keep reading for our debrief.

Created to solve real, timely problems in production-grade applications, Reasonml was built on top of OCaml; a general purpose, industry language created in 1996. Used by the likes of Bloomberg, Issuu and of course, Facebook, OCaml is the technology of choice where speed is vital yet one ‘small’ mistake could cost millions.

Facebook’s story of building on OCaml is by no means unique. A vast list of companies have used/built upon the application, yet Reasonml has still managed to create a storm that’s divided the dev community. On the one hand it’s ideal when working for the likes of the super platforms or in the financial sector, but on the other, it doesn’t seem practical to introduce that kind of syntax within smaller businesses and enterprises who learn as they go. For modest companies, mistakes can be what leads them to success.

Slack is the probably one of the best examples of a start-up doubling down a mistake. The original plan for the team collaboration tool was to be a multiplayer game called Glitch. There were high hopes for Glitch, however it was shut down just a over year into launch. It’s developers citied accessibility issues and depth of gameplay as reasons for closure. Yet whilst Glitch was gone, it’s unique in-game messaging technology remained. Recently reported to be raising $400 million in a new funding round, Slack’s story is testament to business failures leading to great successes.

The History of Reasonml

It began in 2016, when Facebook developer Jordan Walke began to notice just how long people were having to spend rendering their JavaScript code. Having already created ReactJS, Walke wanted to make things easier, asking himself, ‘how can we render user interfaces concurrently and in a way that won’t impact developers?

Deciding to pick up OCaml, Walke immediately fell in love because it helps to understand problems with code, pick up all edge cases and catch corner cases that most devs wouldn’t even think of. But it was when Walke began showing his success with OCaml to others that he saw the issue. OCaml looked entirely alien to JavaScript developers.

Building on OCaml, Reasonml is a JavaScript-friendly syntax that in theory makes writing frontend code more efficient because there are less bugs than something like JavaScript. Gaining fame thanks to Facebook’s decision to use it, Facebook’s reason for Reason (we couldn’t resist) is to reduce the amount of bugs in their code. Minimising the amount of errors, Walke believes that Reason’s well-developed type system provides a higher level of confidence than JavaScript and encourages developers not to mutate their code.

As of 2017, 50% of Facebook’s front end code is written in Reason, with a plan to move the entire stack over as soon as possible. Reason was also awarded the ‘Prediction Award’ in the latest ‘The State of JavaScript’ survey.

The Purpose

Built with React and JavaScript developers in mind, it’s worth taking a look at Reason’s primary purpose. React was originally built by Facebook to ensure that its developers could work more efficiently. And whilst JavaScript is arguably the most popular frontend language, many developers are looking for alternatives; one reason being that JavaScript wasn’t designed to be type safe. A common frustration, the amount of errors that can (and are) made in JavaScript mean that billion dollar corporations, particularly in the financial sector, end up leaning towards languages like OCaml for their products – there’s a real need for the ‘guaranteed’ safety. But whilst Reason may seem like the ideal solution for frontend development, all is not what it seems.

The overarching problem with Reason is that it is so new. There’s not a lot of support for it, and the documentation that is available frequently gets mixed with the documentation from OCaml. It’s frustrating to say the least. Created with the objective to bring developers from different backgrounds together, Reason still feels alien. What’s more, there’s almost an undercurrent feeling within the community that the Reason syntax was made to appease JavaScript devs and is a sugar-coated version of OCaml, instead of solving problems and producing less errors. Walke also admits that Reason isn’t currently very smooth to onboard, and states that there isn’t currently the capacity to improve the process.

Conclusion

Overall, Reasonml is a credible alternative to using just JavaScript, but it’s not the one that you’d necessarily go with. Instead, other syntax such as TypeScript provides more thorough documentation, so it’s more realistic to get started easier and tends to be quicker too. However, it’s great that Facebook are using it and this certainly makes the case for more members of the community to get onboard and create better, more concise documentation. At present it may not be perfect, but thanks to Facebook’s adoption, the future looks bright for ReasonML.

 

Like what you’ve seen? Make sure to read our previous article on our hiring revolution.

Sharing is caring!

Leave a Reply

Your email address will not be published. Required fields are marked *