2 ms·
Scala.js generates significantly larger bundles than Rescript — because Ocaml's semantics map more closely to those of JS, the runtime dependencies are smaller
by yunyu 6y ago
Scala.js generates significantly larger bundles than Rescript — because Ocaml's semantics map more closely to those of JS, the runtime dependencies are smaller and there's a lot of tricks to minimize indirection/overhead. Additionally, interop with npm modules is much less painful with Rescript and bindings for popular third party libraries are more mature. Ignoring the merits of Scala-the-language, there are very good reasons to pick Rescript over the Scala.js toolchain.
Compare https://rescript-lang.org/docs/manual/latest/shared-data-types https://rescript-lang.org/docs/manual/latest/shared-data-typ... with how Scala.js represents arrays and records.
- sjrd 6y agoIn the small, Rescript generates smaller code than Scala.js, that is true. It is mostly a question of the interdependencies in the standard Scala collection library, though, not so much the semantics of the language. And Scala.js also has its share of "tricks" (aka optimizations) to reduce indirections and overhead. Regarding interop and the link you posted, here is the equivalent documentation page in Scala.js: https://www.scala-js.org/doc/interoperability/types.html https://www.scala-js.org/doc/interoperability/types.html Yes, Rescript has more built-in types that map straightforwardly, but that is at the cost of some correctness. For example, using a JavaScript array means that JavaScript can resize it under your feet. Using `undefined` to represent `None` means that you cannot tell the difference between `None` and `Some(None)`. It's a fine trade-off to make. Scala.js happens to make the other trade-off, and offers separate types for JavaScript interop. I like the concepts and design of Rescript, really. It's very interesting because they have all the essential requirements right (IMO) like comprehensive JavaScript interop, while making all the opposite design decisions on nonessential trade-offs compared to Scala.js.
- hongbo_zhang 6y agoHi,some minor corrections. ReScript is more correct than scala, ReScript's type system(essentially borrowed from OCaml) is sound while scala is unsound. > Using `undefined` to represent `None` means that you cannot tell the difference between `None` and `Some(None)` I don't know where you get the impression, of course they are different in ReScript. One thing missed is that ReScript compiler may be 10-100 times faster than Scala.js (I am not kidding)
- sjrd 6y ago> ReScript is more correct than scala, ReScript's type system(essentially borrowed from OCaml) is sound while scala is unsound. Ah, I did not make it clear what I meant by "correct" in this context. I meant "faithful to the original language" (OCaml natively compiled and Scala on the JVM). You are of course right about the type systems. (I believe many soundness holes are fixed in Scala 3.) > > Using `undefined` to represent `None` means that you cannot tell the difference between `None` and `Some(None)` > > I don't know where you get the impression, of course they are different in ReScript. I get that impression from the document linked above, which says that `None` is represented as `undefined` and `Some(x)` is represented as `x`, so `Some(None)` must be represented as `undefined` as well. Oh and `()` too. Do at run-time you can't tell which is which. > One thing missed is that ReScript compiler may be 100 times faster than Scala.js (I am not kidding) Yes, I believe that's true. It is often mentioned as the biggest weakness is Scala, by advocates and detractors alike.