

Scala.js - Write in Scala for the browser - bertzzie
http://lampwww.epfl.ch/~doeraene/presentations/scala-js-scaladays2013/#/

======
benjaminjackman
First of all, if you watched the slides, you just ran the first `hello world`
Scala-js app in your browser. The slides use the scala-js runtime. Developer
tools have scalajs-runtime.js at 1.7MB compressed and about 4s to
download/execute, then about 1.5s on subsequent refreshes.

Now, having seen the talk at Scala days here are a few notes/thoughts:

This is currently the result of 4 months worth of work, and Sébastien
Doeraene, the author of the slides and the code there-in, is going to be
working on it at EPFL for the next 4 years or so for his doctorate.

This is being done by replacing the backend portions of the Scala compiler
that emit java bytecode with ones that emit javascript.

When the slide showing that it is 16MB came up everyone laughed and the author
acknowledged how large a number this is. It is the result of having to bring
in the entire the Scala standard lib. He is planning to work on ways of
cutting this number down.

At the end of talk Martin Odersky commented from the audience that this is an
attempt by the EPFL at making Scala useable for large webapp development. If
it proves successful more resources will put towards supporting it.

I plan to try this out for internal sites used by my company. Currently we
split and then have to duplicate a lot of our code between Scala / Javascript.
Scala for the server software, Javascript for frontends which are webapps. I
haven't had time since I got back to do much more than clone the git repo.

------
beefman
16MB minified. Ok; for what?

"How to scale to Rich Internet Applications?"

Good question. They didn't answer it. Is the Scala code going to be much more
compact? And what problems scaling JS to rich applications were they thinking
of, exactly? They don't say.

~~~
sjrd
Hi,

The slides shown there are, well, slides. They are meant to support a _talk_ ,
and that talk addressed your comments, at least partly. It is also worth
noting that it was Scala Days, and as such I took it for (almost) granted that
the audience is converted to Scala.

The problem is that JavaScript, with its scripting nature, has never been
designed to support programming in the large. The lack of type safety is often
mentioned as one of the major difficulties of JavaScript. That is why there
are other languages targeting JavaScript.

We scale to Rich Internet Applications by using the language Scala, which is a
scalable language. I won't try and make a whole point here. Some people have
moved from Java to Scala for that very reason.

And, yes, the 16 MB are for the standard library. But minifying was only the
first step towards reducing that size. I have at least 4 ideas, which I
believe will each divide that size by ~2. That should bring it down under 1
MB.

~~~
beefman
Thanks for your reply. I would be interested to read the whole argument. I
don't know what "scripting nature" is. JavaScript has first-class functions
and is nearly syntactically identical to Scala. It doesn't have a type system,
but I'm not convinced that's a problem for scalability. Java has a type
system, and you say people are moving away from it because it's not scalable,
so...

------
octo_t
16MB runtime is really painful. Having to pack a huge amount of the standard
library (List is backed by a lot of other traits for example) into the js is
going to be very difficult to reduce.

~~~
bertzzie
Yeah, and I'm not sure scala will be that useful without the standard libs,
much like C# or Java.

Seeing the presentation, I'm thinking more of using it with something like
node-webkit[1] though. Didn't LightTable use clojure-script or something? But
then, why don't just use one of JVM's GUI framework?

[1]: [https://github.com/rogerwang/node-
webkit](https://github.com/rogerwang/node-webkit)

~~~
cgag
I'm doing something for fun with Clojurescript and node-webkit and for me it's
mostly that I want the fast start up time, but also to get to just work with
html instead of having to learn a gui framework.

Also I just want to mention that Clojurescript compiles to javascript that's
compatible with Google's Closure compiler, which can do dead code elimination
and will remove the parts of the standard library that you don't use.

------
rubyn00bie
While in principal, I love this... Because JS is not my favorite language... I
just don't see the real world benefit. It's going to:

1.) increase difficulty debugging (compiled js -> scala) 2.) decrease
productivity, see #1

Why not just write javascript? Though that's my argument against any of these
compile to js kits (coffee script being the big one). So maybe I'm just
trolling (sorry).

Again, super cool. The author is waaay smarter than I for implementing this,
but... The real world.

~~~
cgag
I can only speak for clojurescript, but I'm ok with trading off some debugging
pain for way better semantics / nicer code.

------
lostnet
I enjoy both javascript and scala.

For work and anything I would want to put on a web site it is more practical
to write javascript and when I've had time for my own projects I've enjoyed
scala.

For me this is a great direction. The idea that I'd suddenly replace my
javascript is silly. But being able to pull in things I'm familiar with from
both into the same prototype (and at the same layer) of something and debug it
all in the debugger I'm most familiar with (and with correct code line
references!) is awesome.

Similarly, for someone who is learning scala and doesn't have/want java+IDE
experience, this could lead to learning scala as a language with much less
overhead and/or while learning a more useful combination of debugger and
editor.

I think the overly negative comments come from those who view javascript as
the "problem" that every new way to integrate languages with it must have been
designed to tackle. Since every language has trade-offs, there is always ample
criticism available from that vantage point...

------
srameshc
I hoped for something like clojurescript with Scala. Its finally happening
which is great step. But for now , I am happy with Dart.

------
wiradikusuma
Interesting! Maybe it can learn from Scala on Android:

For Android development, install Scala runtime into rooted phone, so you don't
need to "minify" your code (faster roundtrip). For Scala.js, maybe use Chrome
Extension?

For production, ProGuard (removes unused code in Scala) and Closure Compiler
(optimizes JS).

------
altrego99
I have not used Scala before. What's the motivation for this? I can think of
two reasons - a) to make native Scala programmers feel home with Javascript
and b) Scala is a superior language than Javascript, will therefor make many
things easier.

How much of this is (b)?

~~~
subprotocol
I've used javascript for many many years and, as of 6mo ago, started using
Scala (I do a lot of distributed programming on hadoop, storm, and recently
spark). Scala is now one of my favorite languages because of Spark
([http://spark-project.org/](http://spark-project.org/)). Scala very nicely
blends the functional and imperative styles and it always favors programming
without side-effects. Anything you can do in java you can do in fewer lines
and you will see fewer bugs.

That said- it's not a superior language, just a different paradigm. With Scala
you get very strong typing, functional constructs (so incredibly powerful),
matching, options, very clean closure syntax, etc.. You'll eventually fall in-
love with _, too.

I haven't used scala.js yet, but here are some downsides to Scala proper: *
slow the compile * tooling isn't great (this true of anything jvm to some
degree though)

~~~
mercurial
> tooling isn't great (this true of anything jvm to some degree though)

Well, you have plenty of very decent tools to inspect a running JVM state, and
that's priceless. Eclipse is alright if you manage to set it up once with the
tools you need and don't fiddle with the setup afterwards. Although slow, it
packs a lot more features out of the box than Visual Studio. The debugger is
pretty good too (including remote debugging).

If you compare it to state-of-the-art tooling for more fringe languages like
Python or Haskell, it's lightyears better, really.

------
auggierose
I think that this is a great project, and would be exactly what I need for
ProofPeer ([http://www.proofpeer.net](http://www.proofpeer.net)) because I
have lot's of code that needs to run both on the server and in the browser. I
am using Clojure/Clojurescript currently and am pretty happy with it. But I am
missing the possibility of defining abstract datatypes in Clojure, so my first
choice would have been Scala if Scala.js would already be mature and
reasonably production ready.

------
chii
It'd be interesting to integrate this into the GWT toolchain, so you can write
both java and scala for the browser!

~~~
happy_dino
You mean like
[http://scalagwt.github.io/samples/Showcase.html](http://scalagwt.github.io/samples/Showcase.html)?

------
_progger_
I hope it covers "Debug with breakpoints in Scala for the browser".

~~~
espadrine
He recently announced support for sourcemaps, so yes. Yay!

~~~
_progger_
Cool!

------
sjrd
The video recording is now available!
[http://www.parleys.com/play/51c380bfe4b0ed8770356866](http://www.parleys.com/play/51c380bfe4b0ed8770356866)

------
umren
good job on making this, but.. it's useless

