Compiling _entire Scala_ to JavaScript? Without runtime?! To the point of compatibility that Scalaz can be compiled, with all its horrors?!! Wow.
In your live coding presentation, you mentioned that the output from compiling scala to js is several files.
I'm interested in generating one file that exposed JavaScript functions that can be easily called from a js runtime.
In other words, I'd like to write a JavaScript library in Scala - not a full-blown application.
What are some good resources showing how to do this?
Everything function marked with @JSExport will be exposed to Javascript. There's no concrete difference between an application with one `@JSExport def main` method that you call to initialize it, and a library with multiple `@JSExport`ed methods. It all works the same way: the `@JSExport`ed functions are exposed, and people can call them.
This repo shows how to make a NPM library using Scala.js
- https://github.com/rockymadden/scala-node/
If you want to learn how to use `@JSExport` properly, the [core documentation](http://www.scala-js.org/tutorial/basic/) and [Hands-on Scala.js](http://www.lihaoyi.com/hands-on-scala-js/) are great.
In Java, NullPointerExceptions is huge problem. IDEs have plugins to check for this error, but there is no standard solution.
Does Scala help in avoiding NullPointerExceptions? Do function signatures specify if a value may be null?
var node = element.firstChild;
while (node) {
// do something
node = node.nextSibling;
}
Perhaps those interfaces use the Option class? def printNodes(targetNode: dom.Node): Unit = {
var c = targetNode.firstChild
while (c != null) {
if (c.nodeValue != null) {
println(c.nodeValue)
}
c = c.nextSibling
}
}
The return value from firstChild and nextSibling can be null.Even when it's targeted at the JVM. Scala.JS usage isn't that hard after you read half of the book.
While I consider myself "pretty experienced" at doing web-stuff, and thus knowing the pain-points and constraints and prior work, I have no clue at all what the world of C/C++ is like. Scala-Native is in that world, so someone who has a Scala + C/C++ background would have much better instincts than I would
As a language, it seems pleasant: somewhere around C#, a mix of JS and Java, less "powerful" (or less "crazy" depending on how you look at it) than Scala. I think I personally prefer Scala, but wouldn't complain too loudly if I had to use Dart/Dart instead of Javascript/PHP.
On the other hand, even with Google's backing they seem to not have managed to aggregate as much of an ecosystem in the 4 years they've been available. In particular, server-side-Dart hasn't really taken off, and client-side dart doesn't seem to be that popular compared to say Coffeescript or Typescript or even Clojurescript.
I think the advantage of Scala.js over dart is that we only need to build the JS side of things: there's already a pretty large server-side Scala ecosystem. There's already all the tooling and IDEs set up. There's already the community of people who already know Scala, and do not need to re-learn anything.
Thus even though the Dart-JS ecosystem is probably not that much smaller than the Scala-JS ecosystem, I think Scala-JS is a lot more viable and sustainable (since it can piggy-back on all the Scala-JVM stuff) while Dart-JS and many other new-language communities have a tough struggle to gain enough critical-mass to be self-sustaining
On the other hand Dotty has a lot of very, very concrete benefits I would like. 2x faster compile times for my Scala code sure would be nice...