5 ms·
I wrote this; ask me anything
by lihaoyi 10y ago
I wrote this; ask me anything
- atemerev 10y agoScala.js is magic under magic sauce with magical cherry on top of it. Thank you and everyone else involved! Compiling _entire Scala_ to JavaScript? Without runtime?! To the point of compatibility that Scalaz can be compiled, with all its horrors?!! Wow.
- bcherny 10y agoWhat do you think of using Dotty's effect system for frontend code?
- lihaoyi 10y agoNo clue, as far as I know (as an outsider) the effect system is still in the brainstorming phase with not much pinned down or concrete yet. 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...
- bcherny 10y agoThat's fair. Personally, I'm excited to have another way to manage side effects on a platform that has so many of them.
- edko 10y agoWould you bet as much on Scala Native?
- lihaoyi 10y agoI can't say, really. I have written a lot of Javascript/Coffee/Java/Scala/C#/F#/Python/PHP, and made a bunch of crappy websites, but I have never written any code in a language that compiles to assembly (500 lines of C in 20-50 line snippets for various classes probably doesn't count). 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
- labrador 10y agoWhat do you think of Dart? I need to know this for reasons I can't go into.
- lihaoyi 10y agoNever used it but it seems like a plausible project; it has Google's infinite $$$ backing it and smart people like Gilad Bracha on the team. They've built up quite a lot (language, tools, package-manager, IDE, ...) from scratch which is pretty impressive. 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
- labrador 10y agoI was full in for Dart but Scala.js has been one of those alternatives that seemed more viable. Thanks!
- apo 10y agoAmazing work - thanks for putting it out there. 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?
- lihaoyi 10y agoThe live coding presentation is two years out of date; Scala.js now compiles to a single JS blob 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/ 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/ http://www.scala-js.org/tutorial/basic/) and [Hands-on Scala.js](http://www.lihaoyi.com/hands-on-scala-js/ http://www.lihaoyi.com/hands-on-scala-js/) are great.
- saosebastiao 10y agoNo questions, just praise. I love your scala work, and would love to take my company far enough to be able to approach you to work full time writing scala.
- difftest 10y agoSincere praise!
- nilknarf 10y agoGreat post! Just curious, why didn't you include emscripten (C/C++) in your comparisons?
- curious2learn 10y agoWhich resources (books/tutorials) do you recommend for learning Scala.js for someone who does not know Scala or Java or any JVM language, but knows a decent amount of Python, Julia, Go, Javascript, Dart etc. I should add that I am not interested in JVM (at least, now). I want to know what are good resources if one intends to use Scala only for the JS side of things.
- merb 10y agoActually you should start out with https://www.amazon.de/Programming-Scala-Martin-Odersky/dp/0981531687 https://www.amazon.de/Programming-Scala-Martin-Odersky/dp/09... Even when it's targeted at the JVM. Scala.JS usage isn't that hard after you read half of the book.
- oever 10y agoClosure Compiler uses type annotations on variables and functions that give information on null and undefined. These annotations look like {?Object|undefined} (Object may be null or undefined) and {!Object} (object is guaranteed to not be null). 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?
- gmartres 10y agoScala does not have non-nullable types currently (but that might happen in the future), in practice this is not a problem simply because using null is seen as a code smell and basically no Scala library API expects parameters to be null or return null, optional values are usually represented with the standard library class Option: http://www.scala-lang.org/api/2.11.8/#scala.Option http://www.scala-lang.org/api/2.11.8/#scala.Option
- oever 10y agoOne of the main points of the blog is that Scala.js integrates well with the JavaScript apis and those apis are full of null. A typical loop in the DOM looks like this: var node = element.firstChild; while (node) { // do something node = node.nextSibling; } Perhaps those interfaces use the Option class?
- oever 10y agoI wrote a small test function. It appears that Scala.js has no default protections against null values from the browser DOM. 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.
- deleted 10y ago[deleted]