Live data from Hacker News

Scala.js 1.0.0-RC1

scala-js.org

11–20 of 59 posts

Re: Scala.js 1.0.0-RC1

#11
post #9

Anyone know what's the minimum size of the compiled JS now? Is there any way Scala.js can produce code as compact as BuckleScript/ReasonML in the future? I like Scala's syntax but the last time I tried Scala.js, the output was several hundred kb for something slightly more than a Hello World -- it used some List and Seq functions. I'd bet the comparable ReasonML output would likely be in tens of kb (including List an…

The bare minimum for a hello world is 6 KB (before gzip). But of course as soon as you start using Scala collections, it's getting bigger. The minimum for a realistic application is 90 KB (before gzip). That's less than your typical JavaScript framework, so for any realistic application it shouldn't be a concern.

For refernce- Jquery unzipped is similar size- 87K and while it adds much more functionality, Scala collections easily trump jquery's in usability and power.

SJRD, Would you also add a bit more info about how this size increases? I haven't cared much but it seems from your comments that the slope should be much less once you reach 90kb.

Re: Scala.js 1.0.0-RC1

#12
post #9

Earlier quoted context omitted.

The bare minimum for a hello world is 6 KB (before gzip). But of course as soon as you start using Scala collections, it's getting bigger. The minimum for a realistic application is 90 KB (before gzip). That's less than your typical JavaScript framework, so for any realistic application it shouldn't be a concern.

For refernce- Jquery unzipped is similar size- 87K and while it adds much more functionality, Scala collections easily trump jquery's in usability and power. SJRD, Would you also add a bit more info about how this size increases? I haven't cared much but it seems from your comments that the slope should be much less once you reach 90kb.

Yes once you're at 90 KB the slope will be much less. It will simply grow with the actual code of your app.

Re: Scala.js 1.0.0-RC1

#13

As someone who has dropped Scala on the backend (not doing FUD, just not happy with the JVM memory reqs)- what keeps me still using scala is Scala.js. While some argue that there is more readable code with Bloomberg's OCaml.js, I like Scala.js because of Scala itself, which is 1) Very well designed 2) Lots of "functional" constructs in accompanying libraries 3) Good typechecking 4) Fun language to use. and because Sc…

> just not happy with the JVM memory reqs

Are you not happy with JVM in general or not happy with how Scala uses the JVM? Things like Spark were written in Scala so I am curious what didn’t work for you.

Re: Scala.js 1.0.0-RC1

#14

Anyone know what's the minimum size of the compiled JS now? Is there any way Scala.js can produce code as compact as BuckleScript/ReasonML in the future? I like Scala's syntax but the last time I tried Scala.js, the output was several hundred kb for something slightly more than a Hello World -- it used some List and Seq functions. I'd bet the comparable ReasonML output would likely be in tens of kb (including List an…

Why these rules are violated?

[deleted]

Re: Scala.js 1.0.0-RC1

#15

Anyone know what's the minimum size of the compiled JS now? Is there any way Scala.js can produce code as compact as BuckleScript/ReasonML in the future? I like Scala's syntax but the last time I tried Scala.js, the output was several hundred kb for something slightly more than a Hello World -- it used some List and Seq functions. I'd bet the comparable ReasonML output would likely be in tens of kb (including List an…

While i understand your concern, i wouldn't use scala.js in a context where several hundred kb are an issue. I've tried it and it works great, but i think it only pays of if you implemented a complicated web-app with complicated server-side code, e.g. if you replace a desktop-application to manage some system with a web-based one. Something where showing a loading-screen on the first visit is totally reasonable.

Re: Scala.js 1.0.0-RC1

#16
post #6

As someone who has dropped Scala on the backend (not doing FUD, just not happy with the JVM memory reqs)- what keeps me still using scala is Scala.js. While some argue that there is more readable code with Bloomberg's OCaml.js, I like Scala.js because of Scala itself, which is 1) Very well designed 2) Lots of "functional" constructs in accompanying libraries 3) Good typechecking 4) Fun language to use. and because Sc…

ClojureScript too, if you don't mind dynamic typing.

Yeah, ClojureScript is amazing.

Re: Scala.js 1.0.0-RC1

#17

Anyone know what's the minimum size of the compiled JS now? Is there any way Scala.js can produce code as compact as BuckleScript/ReasonML in the future? I like Scala's syntax but the last time I tried Scala.js, the output was several hundred kb for something slightly more than a Hello World -- it used some List and Seq functions. I'd bet the comparable ReasonML output would likely be in tens of kb (including List an…

Scala.js is being fed to the Google Closure compiler [1] for minification via tree-shaking, after applying optimizations on its own. Output can be unreadable, but debugging works via source maps.

It's not perfect, but you should not get hundreds of KB for a Hello World. And indeed, the code cannot be as minimal as hand crafted code either.

Note that this is often a false problem, because people often use a lot of JavaScript libraries without any tree-shaking in their build process, so if you do care about tens of KB, then you don't use JQuery, React, etc. A valid use case indeed, I've been there, but not for your typical app.

[1] https://developers.google.com/closure/

Re: Scala.js 1.0.0-RC1

#19

Can this call js libraries and the DOM trivially like typescript? Or does it leverage ffi?

You can call js directly using dynamic. From the docs[1]:

    val document = js.Dynamic.global.document
    val playground = document.getElementById("playground")
    val newP = document.createElement("p")
    newP.innerHTML = "Hello world! -- DOM"
    playground.appendChild(newP)

1. http://ochrons.github.io/sjs2/doc/interoperability/calling_j....

Re: Scala.js 1.0.0-RC1

#20
post #5

Can this call js libraries and the DOM trivially like typescript? Or does it leverage ffi?

It's exactly like TypeScript. You write type definitions or you find them online, like in TypeScript, then you can call any JavaScript API using the relevant types. Full relevant docs at https://www.scala-js.org/doc/interoperability/

Many TypeScript type definitions are also automatically converted to ScalaJS: https://github.com/oyvindberg/ScalablyTyped
Post reply on HN