Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Scala.JS 0.6.17 released (scala-js.org)
89 points by scalatohaskell on June 4, 2017 | hide | past | favorite | 59 comments


Scala.js has been an amazing tool for my personal projects. I literally hit euphoria sometimes writing stuff in it. I am yet to truly grasp the benefits of full stack Scala (shared models, Autowire, etc.) but even for purely front-end development it's great, it beats Typescript and Flow out of the water in features, soundness and stability.

I wish I could use it at work since we (Hootsuite) already use Scala heavily on the backend, but I am reluctant in part because Scala.js does not quite have financial support of Lightbend. Or so it seems, it's a bit hard to tell where Lightbend ends and the non-profit Scala Center begins. The latter did pay to get some features implemented but reading their advisory board minutes, I'm not sure if they would have enough funding to pay for the majority of Scala.js development, which if I understand correctly happens for free as part of a PhD right now (note: my information might be wrong/outdated!)

So, if anyone involved with Scala.js is reading this and has better insights on the situation, it would be nice to know.

But I will keep using it regardless. It's marvellous.


You are mostly accurate wrt. the "financial" situation of Scala.js. Except that the Scala Center has an explicit Recommendation to "ensure the continuity of Scala.js" [1]. At least that means that, should I (the Ph.D. student doing Scala.js right now) stop working on it, the Scala Center has a mission to ensure someone keeps working on it. As with all Scala Center Recommendations, this is not a guarantee. But given the popularity of Scala.js within the Scala eco-system, I am confident that solutions will be found! Read more about the Scala Center and how it works at [2]

[1] https://github.com/scalacenter/advisoryboard/blob/master/min... [2] https://scala.epfl.ch/


> the Scala Center has a mission to ensure someone keeps working on it.

Heh, I hope it's you! :)

Seriously, scala.js has been amazing for us! Thank you for all that hard work!

EDIT: Of course you might still be beaten out by scala.native -> WebAssembly -> Browser... nah, not really. :)


(Too late to edit my comment.)

Were you at ScalaDays 2017 CPH? I don't think I saw you there, but you deserve a round of applause, you Magnificent Bastard, you!


Thank you. No I wasn't there this year. I was furiously preparing this release :-p

See you probably in London for Scala eXchange ;)


Thanks! You know, if it comes to that, Scala.js community is a passionate bunch, we could probably crowdfund it :)


It would be shocking if they hired anyone but the creator of Scala.js -- hopefully after you finish your doctorate this winter Lightbend and/or Scala Center will step up and make it happen.


What if he wants to quit scala.js and go code trading bots to get filthy rich :)


Unlikely. I love compilers too much.


I work in a trading shop (not filthy rich yet, though). Do you know that Scala to FPGA compilers based on Chisel are all in vogue these days? ;)


Ah ah!


Are there any public Scala to FPGA compilers?



> I am reluctant in part because Scala.js does not quite have financial support of Lightbend. Or so it seems, it's a bit hard to tell where Lightbend ends and the non-profit Scala Center begins.

As the Scala team lead at Lightbend, I'd love to have a few members of my team focus on scala.js and scala-native. We do financially support their development (most recently, as part of our funding of the Scala Center).

As a business, it's a bit of a chicken-and-egg problem: our customers usually indicate they are hesitant to switch from JS for their frontend work. It would be great to have more customers provide feedback like yours (via our customer surveys)!


If I was Lightbend (whose work I use/enjoy/thank for) I think I would put Scala.js inside the Play Framework (as opposed to say Coffeescript)



I am exactly in same situation and experiences with Scala.JS as you... my #1 choice atm.



This looks pretty good, but Google trends doesn't show any growth for functional languages over the years :(

https://trends.google.com/trends/explore?q=scala%20programmi...


Looks like it has peaked to me..


Scala.js author here. Ask me anything ;)


Do your know that you have done the impossible and single-handedly revived Scala? It was slowly dying two years ago, with all that Dotty uncertainty and Typesafe->Lightbend transition.

Then you came and showed us that Scala can be productively used beyond JVM. A new hope appeared, Scala-native was inspired by your example, and Dotty was upgraded from a purely academic exercise to a viable pragmatic way to Scala 3. The attitude was "if Scala.js guys did it, so can we".

So thank you, from me and all Scala hackers out there. Martin owes you a beer. :)


> Typesafe->Lightbend transition

The renaming never affected the staffing of the Scala team at Lightbend -- we've been doing about 2/3 of core Scala development (major thank you to the community for the other third!) since 2.10 (when I went from post-doc in Martin's lab to the Scala team lead position).

In my opinion, it was a good thing that feature development slowed down in Scala 2.x (while Martin pushed the research frontier forward in Dotty), so we could focus on (in no particular order) compiler performance, a new back-end and optimizer, Java 8 support, modularization,...


Facilitating contributions from the Scala community, what can be improved:

[0] https://github.com/scala/scala/pull/5515

[1] https://failex.blogspot.nl/2017/04/why-i-didnt-sign-scala-cl...


Yes, it all went in a good way. However, this was a scary time, observing Typesafe (now Lightbend) slowly transforming into a garden variety enterprise Java consulting shop, and watching more and more core platforms like Akka being adapted back to Java...

Things look better now. :)


Good to hear! I agree :-)

It was a necessary transition because we need to keep attracting customers that initially are reluctant to invest in Scala training. We've found our Java APIs to be a potent gateway drug to Scala, with many of our customers who begin with the Java APIs quickly realizing they'll be even more productive with Scala :-)


Thank you for your kind words :) It's always nice to see that one's work is appreciated!


Is there any way or anything in the works that would allow dealing with JSON without relying on libs that originated on JVM? They always feels like quite a bit of an overkill considering that underlying platform is JS.


Sure, you can just use `js.Dynamic`, or write `trait`s describing the "schema" of your JSON, and of you go. Let's say you have have an array of Persons with a name and age, you can type it as:

    @ScalaJSDefined
    trait Person extends js.Object {
      var name: String
      var age: Int
    }

    type Persons = js.Array[Person]
Done deal. With the new option `-P:scalajs:sjsDefinedByDefault` of this release, you don't even need the `@ScalaJSDefined`.


thanks -P:) awesome! takes circe out of the equation when talking to graphql which is already "typed"


The in-process Scala collections library overhaul, what impact will that have on Scala.js when Scala 2.13 lands?

From what I've seen so far there hasn't been much in the way of removals. Ideally the compiler and standard library would be as small as possible in order to help Scala.js streamline generated application binaries.


Hopefully the new design means less interdependencies between all the collections. That would mean that the reachability analysis of Scala.js could be more aggressive in its dead code elimination.


Does anyone use this?


Sure, replacing a legacy Coffeescript + jQuery app with pure Scala.js. Implementing core functionality of various jQuery plugins (Datatables, Validation, FancyBox, Bootstrap Date/Time pickers, etc.) in Scala.js. Payload is less than 50% of previous version's app bundle. You can of course pull in client-side libs as you like, but for this project it's been really nice to strip out the bloat.

Having Scala's type system on both client and server is pretty surreal, not to mention full IDE support -- the entire world of javascript just appears as you type ;-)


What's the generated file size after gzipping for the project compared to coffeescript + jquery if I may ask?

Also, can scala.js be used for progressive enhancement on static sites, or is it limited to single page apps due to the need to map scala semantics to js?


Well, for one, the world's 3rd biggest software company, SAP. See http://event.scaladays.org/scaladays-cph-2017#!#schedulePopu... - quote: "The application development stack we are building embraces Scala all over the place – including the development of user interfaces for which Scala.js is utilized to provide a type-safe interface to SAP's own JavaScript UI library SAP UI5."


Yes, we do, and we love it.

If you know Scala, you can mostly forget about Javascript and just code everything in Scala both on server and client side, and everything just works magically (using the same data types is PURE PINK UNICORN AND RAINBOW BLISS). If you don't know Scala, your mileage may vary, but I'd learn a bit of Scala just to experience that.


Yes, for quite a few projects.

For a number of them I used scala-js-react, though very recently (as of about two weeks ago) I've been playing around with my own (smaller, less opinionated) virtual dom library. http://www.wbillingsley.com/veautiful/


yes, several personal stuff, some internal facing business apps , and few public facing I did as contractor.

It's a whole different world than anything else in frontend. The libraries from scala are immense.


We use Scala.JS in production, and so far we haven't had a single issue with it. Cross-JS/JVM projects have hairy .sbt files though.


yes, I've one big project in it. Currently working with: ui -> scalatags, serialisation -> upickle.


Sad that Scala.js will not use WebAssembly, since WebAssembly doesn't provide GC.


WebAssembly will most likely eventually provide a GC, at which point we'll do what we can to support compiling to wasm.

See also: https://github.com/WebAssembly/gc/pull/1#discussion_r1109978...


They don't seem be on Chrome roadmap. We'll all grow full beards by the time DOM and GC become available. https://wasmdash.appspot.com


GC support can hardly be on Chrome's roadmap when the design of the spec has hardly anything more than "we want to have it, and here are some vague goals".

So yes, we'll grow beards, but it will happen. Remember though that wasm as whole happened in only a few years!


My two cents: to me WebAssembly seems like something Scala Native might address, more than Scala.js. Or even better, both project can sort of blend for this purpose as on one hand (SN) addresses LLVM compilation and the other (SJS) is perfect JS interop (not so sure how WebAssembly does that).


> not so sure how WebAssembly does that

Basically: badly. That's the number one reason we're not trying to compile Scala.js to wasm at the moment. For wasm to get the level of JS interop that Scala.js has, it needs to integrate with JS objects, which means with the JS GC, which means basically have a GC of its own. Hence we're waiting for the wasm GC spec to take life :)


I, sort of, know the limitations WebAssembly has right now when it comes to JS interop (such as only being able to use functions with numbers as parameters!) but my guess is this is temporary. It'd be curious to see experiments doing something Scala Native -> Emscripten -> JS-land.

Regardless, thanks so much for the work you're doing with Scala.ks (Scala is still my main language and I'm working on removing JS from my toolbox soon).

https://youtu.be/HktWin_LPf4?t=22m31s


Scala.js could write their own GC to hook into WASM as a library, and ship it with Scala.js until WASM has its own GC. Indeed, such competition could spur on the the WASM team(s) to accelerate work on GC.


That would not solve that essential part:

> it needs to integrate with JS objects, which means with the JS GC

Otherwise we would have done it already.


Could you not have a radical separation between data to be collected by Scala.js GC, and data GCed by Javascript? Data that crosses the boundary is deep-copied so as to avoid interference between both collectors?

Not good for performance, but possible in principle, and a stop-gap measure until the WASM GC lands.


I'm not sure what you mean by "deep-copied" in this case. But I suspect it would involve losing the identity of the objects, which is unacceptable for correctness.

Moreover, typical Scala.js code constructs cyclic dependencies between Scala objects and JS objects routinely. If Scala.js has its own GC, you'll have to manage those cyclic heap references, which will involve weak maps and other trickery so complicated that we would most likely lose all the performance that wasm would otherwise bring us.

It's just not worth it.


What do you exactly expect from targetting WASM instead of JS? Higher performance? Smaller bundles and faster load times? Better interoperability?


Better interoperability, definitely not. Scala.js already has the best interoperability out there, excluding languages with the same run-time semantics as JS (such as TypeScript). In fact, it is the lack of good interoperability in wasm that currently prevents us from compiling Scala.js to that target.

We could hope for smaller bundles and faster load times, yes. But mostly we should be able to get faster "cruising" execution. Scala.js being statically typed, there is a lot of static guarantees that we lose when compiling to JS. JS engines are very good and can "recover" a lot of it through JIT'ing, but it's still 3x slower than Scala/JVM on average (after warmup of both), so clearly we lose something non-negligible. By compiling to wasm, we would lose the JIT, but keep the static types. It is unclear how fast we would manage to be, but I would hope we can get within 2x of the JVM instead of 3x-ish.

There is a lot of misconception on the Internet that "wasm makes everything faster". For example, a lot of people want to "compile JS down to wasm" to make it faster. That's bullshit, because your language does not have static types to begin with, so you lose the JIT and gain nothing in exchange, which means you'll run much slower. But if you compile a statically typed language down to wasm, you should be able to gain some significant speed.


> a lot of people want to "compile JS down to wasm" to make it faster. That's bullshit, because your language does not have static types to begin with, so you lose the JIT and gain nothing in exchange, which means you'll run much slower.

According to Mozilla's recent blog[1], WASM will in many cases be faster than JIT. In your experience is this not true?

[1] https://hacks.mozilla.org/2017/02/what-makes-webassembly-fas...


I read that article. They do not say anything wrong. But if you read between the lines, the article assumes your source language has types and does not have managed memory. Under those conditions, wasm will beat the JIT every time.

But if your language has dynamic types and/or managed memory (but mostly dynamic types), then you need a JIT to get anywhere close to decent performance.

The silent assumptions in that quite famous article is one reason many people believe that "compiling JS down to wasm" will make it faster. It is not the only article that has completely failed to point out the limitations, though. It's very sad to see, from where I stand.

Note that I am not the only one thinking this. Core wasm developers agree. [1]

[1] https://github.com/WebAssembly/design/issues/219


thanks, TIL. That Mozilla blog is misleading.


Yeah, but Scala started out on a JIT runtime. I'm skeptical a non-JIT would really be that much better.


As I said in the parent, in the case of Scala.js, I believe we lose more performance because of the loss of static types than we would if we lost the JIT.

Performance measurements in Scala Native, which has no JIT and is still quite young (so not very optimized yet), suggest than we can easily be within 2x of the JVM for Scala code, even without JIT.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: