Cover image by 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 that came with a bunch of syntax updates.
let myFunction myArgument => ...
becomes
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!
myFunction "Hello";
becomes
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.
{
add: fun a b => a + b
}
becomes
{
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.
let myFunction ::url ::method => ...
becomes
let myFunction = (~url, ~method) => ...
On the call site it was changed too.
myFunction ::url="http://dev.to" ::method="POST";
becomes
myFunction(~url="http://dev.to", ~method="POST");
String concatination is now ++
so
"abc" ^ "def"
becomes
"abc" ++ "def"
Different from the JavaScript version, but a bit closer to +
I guess.
The negation operator also got a more JavaScript like representation
not expression;
becomes
! 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 ()
myFunction ();
becomes
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.