Reason got an Update
Tags: reason, javascript, code
Published: 2017-10-30 08:11:59

---
title: Reason got an Update
published: true
description: Reason now looks even more like JavaScript
tags: reason, javascript, code
cover_image: https://thepracticaldev.s3.amazonaws.com/i/9shw3vzazxcp49xjndta.jpg
---

_Cover image by [GotCredit](https://www.flickr.com/photos/gotcredit/) on Flickr, cropped by me._

As you may heard, Facebook is out to do its own thing on functional programming languages. They created Reason, a language with the power of OCaml, but a more JavaScript like syntax.

Now this new language was [lifted to version 3](https://reasonml.github.io/community/blog/#reason-3) that came with a bunch of syntax updates.

```javascript
    let myFunction myArgument => ...
```

becomes

```javascript
    let myFunction = (myArgument) => ...
```

Which looks a bit saner coming from JS, I think. The old version somehow looked a bit like a mix of a regular function definition where `let` is used instead of `function` and a arrow function definition, all without parenthesis.

Also, there are changes on the functions call site, more parenthesis for everyone!

```javascript
    myFunction "Hello";
```

becomes

```javascript
    myFunction("Hello");
```

I did a few projects in LiveScript, back in the pre-ES2015 days, and grew rather fond of the minimal syntax, but I have to admit, often parenthesis help to make things a bit clearer.

The arrow functions got an update too.

```javascript
    {
      add: fun a b => a + b
    }
```

becomes

```javascript
    {
      add: (a, b) => a + b
    } 
```

Again, a question of taste, but yes if you know JavaScript, you'll pretty much feel at home here.

Then there are the named arguments. They are a bit like when you make a function in JavaScript, that takes an object instead of multiple arguments, so you don't have to adhere to the position of the arguments _and_ see on call site what each argument is called.

```javascript
    let myFunction ::url ::method => ...
```

becomes

```javascript
    let myFunction = (~url, ~method) => ...
```

On the call site it was changed too.

```javascript
    myFunction ::url="http://dev.to" ::method="POST";
```

becomes

```javascript
    myFunction(~url="http://dev.to", ~method="POST");
```

String concatination is now `++` so

```javascript
    "abc" ^ "def"
```

becomes
 
```javascript
    "abc" ++ "def"
```

Different from the JavaScript version, but a bit closer to `+` I guess.

The negation operator also got a more JavaScript like representation

```javascript
    not expression;
```

becomes

```javascript
    ! expression;
```

Also, calling a function without parameters required to pass it `()` which kinda looked like calling it in JavaScript even tho the concept seemed to be a bit different, but there was a space between the function name and the `()`

```javascript
    myFunction ();
```

becomes

```javascript
    myFunction();
```

A minor change, but these tiny seemingly useless spaces probably gave people the heebie jeebies.

## Conclusion

Reason moves more and more from OCaml to JavaScript, so starting with it has never been easier. Many people have complained about getting rid of the cool OCaml syntax and cluttering it with JavaScript trash, but I think this syntax convergence is a must for adoption.

Also, OCaml doesn't go away and I already heard that people started with Reason and switched to OCaml later, because they found the syntax more light weight.