BuckleScript vs Js_of_ocaml transpliation
BuckleScript is a tool to compile from OCaml to JavaScript. It is different to Js_of_ocaml which compiles ocaml bytecode
to JavaScript. Instead, BuckleScript transpiles OCaml syntax into JavaScript directly. The result is a smaller footprint and very readable code.
Above is one-liner on OCaml hello world, now see the transpiled result from Js_of_ocaml
Not only the message is cryptic, it won’t run without jsoo_runtime
loaded. Now take a look at the result from BuckleScript
The BuckleScript result also depends on standard library. But look at the code it produced.
Practically, we don’t use print_string for JavaScript program. Instead, we ought to use Js.log which is the library that provided by BuckleScript. Js.log will directly be translated into console.log in JavaScript, so no overhead or library footprint.
In my opinion, BuckleScript is more suitable for web development where you start a project from scratch. But if you already have a full project in OCaml. Js_of_ocaml can be a better solution since it transplies all modules required.