why I like scala.js

why I like scala.js

scala.js is a scala compiler that compiles scala to javascript. There are many languages out there that compile to javascript.

So why do I like scala.js? You’ll see that my argument could probably be made for other transpilation-capable languages as well.

In no particular order:

  • I already know scala so this allows me to re-use my skills.
  • I was tired of JVM issue and uncertainties about its future. Although Oracle now seems to be investing in the JVM ecosystem, I am wary of historical trends. Also, the JVM is not critical in some types of program architectures. The other aspect is that scala has remnants of the JVM built into it. Life is tough, but I found that JS handles some things differently that I liked better, such as not forcing errors into a specific type (JVM only allows errors to be Throwables).
  • Built on javascript, scala.js interop with javascript allows me to remove a large category of thorny issues that nearly all JVM languages have–how to adapt language constructs and semantics to general purpose data structures used in a wide variety of libraries that improve my productivity . This is actually a really big deal for me. Since one class of application that I care about are web front ends (as well as backends since I am a data scientist), the use of javascript with scala.js interop allows me to translate scala level constructs into a common data format that is easy to work with. JSON is everywhere in javascript. And like with Lisp, where lists and dictionaries were flexibly and builtin as foundational data structures that all lisp libraries used with great flexibility, you can turn scala level data constructs into JSON easily. This allows you to avoid using/building complex serialization/deserialization libraries as well as avoid some aspects of data management libraries. For example, creating diffs of objects or breaking an object into dictionary and back again in a typesafe way sometimes requires complex introspection or compiler macros–in javascript most people could write their own or some variant that is good enough to get work done.
  • scala.js works well.

We all have opinions about javacript and JSON–that’s Ok.

From my perspective, javascript/JSON is good enough on both the server and a javascript agent like a web browser to make programming easier and less complex for certain types of applications-not all. Using scala.js allows me to obtain benefits of scala semantics and ecosystem while still using the interop to javascript/JSON to take advantage of the strengths in the javascript/JSON of the ecosystem. I do not need extra macros, complex libraries or other things that are necessary when using a JVM language when performing some data operations.

I do not need everything perfect and programming will never be perfect. The incremental benefits of using scala.js are good enough for me to improve my productivity and ability to deliver better client solutions faster.

That’s it!

PS Yes, I keep track of other languages that also have javascript capabilities like ReasonML (OCaml), dart, clojure, typescript, Haskell (kind-of). In strategy terms, scala.js allows me to stay in the scala ecosystem whereas I would have to leave scala to do something that requires javascript. Once you leave the ecosystem, even for part of the work, you are at risk for churning a programmer to another language and ecosystem in their entirety.


Popular posts from this blog

zio layers and framework integration

typescript and react types

dotty+scala.js+async: interesting options