Live data from Hacker News

From first principles: Why I bet on Scala.js

lihaoyi.com

21–30 of 90 posts

Re: From first principles: Why I bet on Scala.js

#21
post #18

For people who want to do typed functional programming on JS platform, there is another candidate: BuckleScript for OCaml: https://bloomberg.github.io/bucklescript/js-demo/ The compiler is compiled into JS and native code. It generates highly readable JS code and easier FFI. It compiles super fast (generally 10~100 faster than Scala) and generates optimized code.

there's also elm and purescript, both of which are haskell likes

Re: From first principles: Why I bet on Scala.js

#22
post #13
post #12

Earlier quoted context omitted.

What do you think of using Dotty's effect system for frontend code?

No 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...

That's fair. Personally, I'm excited to have another way to manage side effects on a platform that has so many of them.

Re: From first principles: Why I bet on Scala.js

#23
Article is a total tour de force.

The OP has contributed so much to the Scala community; somehow he's a Python + Coffeescript developer by day, and an absurdly prolific Scala library author in the evenings.

As for Scala.js, representing browser interactions in types is such a relief, and to have the entire Scala language available is almost too good to be true: client-server interop is seamless.

Really the only negative for me is the Scala collections library. Of the @100KB Hello World[1] generated blob half of that is Scala collections. There's a small initial "tax" to pay basically, and thereafter size increase is on par with normal javascript.

[1] not totally true, vanilla Hello World is more like 40KB, but once you define a Scala collection then generated blob doubles in size.

Re: From first principles: Why I bet on Scala.js

#24
post #19
post #3

I wrote this; ask me anything

Would you bet as much on Scala Native?

I 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

Re: From first principles: Why I bet on Scala.js

#25
post #4

3 things I don't like about Scala: 1. It's based on the Java platform. 2. It's excessive use of operator overloading. 3. Mad implicit conversions all over the place. (yes, I exaggrated a bit ;))

> 2. It's excessive use of operator overloading.

Overloading at least some could be useful. Java 10+ will probably allow something like this, too. You ever worked with BigDecimal?

In Python, Scala where + (__add__) is overloadable you do.

    BigDecimal(1) + BigDecimal(2) + BigDecimal(3)
On Java:

    (new BigDecimal(1).append(new BigDecimal(2)).append(new BigDecimal(3)
I think you get the point..

Re: From first principles: Why I bet on Scala.js

#27
post #18

For people who want to do typed functional programming on JS platform, there is another candidate: BuckleScript for OCaml: https://bloomberg.github.io/bucklescript/js-demo/ The compiler is compiled into JS and native code. It generates highly readable JS code and easier FFI. It compiles super fast (generally 10~100 faster than Scala) and generates optimized code.

and Fable for F# https://github.com/fsprojects/Fable

Re: From first principles: Why I bet on Scala.js

#28
post #3

I wrote this; ask me anything

What do you think of Dart? I need to know this for reasons I can't go into.

Never 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

Re: From first principles: Why I bet on Scala.js

#29
post #3

I wrote this; ask me anything

Amazing 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?

Re: From first principles: Why I bet on Scala.js

#30
post #29
post #3

I wrote this; ask me anything

Amazing 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 thi…

The 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/

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.

Post reply on HN