Hacker News new | past | comments | ask | show | jobs | submit login

I love this trend of building compilers for existing languages that target Javascript. Other 2 languages with fully functional Javascript compilers that are worth checking out:

- Scala / Scala.js (http://www.scala-js.org/) and I'm actually using this one for a non-trivial app

- Clojure / ClojureScript (https://github.com/clojure/clojurescript) with some companies using it in production

Both are using Google's Closure compiler to do tree shaking minification and are emitting source maps for the compiled code, so the size of the compiled artifacts is manageable in spite of the huge standard libraries they come with and debugging works well. Normally if you want tree shaking with Google Closure, you have to write code specific for Google Closure, however these compilers are doing that for you.

What you get in comparison with Javascript are saner languages that aren't just a prettified Javascript - completely different type system, awesome standard libraries, packages, saner semantics overall; you get a sane dependency management and build process, by means of their build tools (SBT and Leiningen respectively); you get libraries that are cross-compiled for the JVM and Javascript, so you can do code sharing between the server and the browser and you can use mostly the same tools, like IDEs. For example it's a great experience to use IntelliJ IDEA for targeting the browser with Scala - you get code completion, refactoring, the works.

And yes, the compiled size of the final artifact is a source of worry, but in practice I found to not be an issue and what's awesome is that in the long run it actually saves bandwidth for heavy apps. With Javascript many people tend to avoid using third-party libraries, because every imported library adds to the download size, however with tree shaking you're paying only for what you use. As I mentioned, being a Scala developer I picked up Scala.js and it's completely awesome, in spite of the project being young. Unfortunately these heavier alternatives to Javascript haven't picked up popularity - for some reason people preferred putting lipstick on Javascript and pretend that it's a new language.

I'm happy that compilers for C# are happening as well. My only gripe is that in true .NET fashion I'm not seeing a link to the source, which makes me think that this won't be open-source. Which is a pity.

List of languages that compile to JavaScript


If you use all features of scala you get at least 16mb pure js boilerplate. Even with dead code elimination you cant get below 100kb with 10 lines of scala. Im not sure if i would call that manageable. Your app might explode into megabytes at one point.

With es6 around the corner and the possibilities those features will provide, i would still bet on pure js. Those precompilers will benefit a great deal too. Symbols and Proxies alone will remove a lot of the hoops they have to go through now.

It's technically impossible to use all of Scala's features and if you do, you'd pay the same price with equivalent Javascript libraries.

I don't get this argument on the size of a hello world, given that JQuery 1.11 is over 270 KB and most people are just doing simple DOM selection with it, yet they don't complain their hello world comes with 270 KB of stuff they'll never use. Factor in React, Bootstrap, Angular.js or what have you and you can easily reach 1 MB of stuff that's never used for a couple of lines of code.

The app doesn't explode in MB, unless those MB are really needed - which is the fundamental difference between how these work and regular Javascript development. And given that there are some companies using these in production for non-trivial stuff and that nobody has ever reported that, I'm thinking that it doesn't happen.

My current app is currently clocking at 300 KB btw, but I am using the collections from the standard library, I am using a library for reactive streams built by myself, I am using React and I do have some code in it. And personally I find it OK.

In theory, jQuery can be brought in by reference from Google Hosted Libraries or cdnjs or whatnot, cached for a long time, and reused in any other website that uses the same external host and version. You can't say the same about your tree-shaken thingy... However, I'm not experienced enough to say how well that works in practice.

It really doesn't work out well, especially where it matters - on mobile phones with poor connectivity. Why do you think alternatives like Zepto.js exist?

Is that 300 KB minified and gzipped? I'm interested in scala.js but concerned about size.

Minified/optimized, but not gzipped. Size will depend on what you do with it. But play with it, see how it behaves, it's fun anyway.

Just want to bring it up, funscript (http://funscript.info/) has been around for a while for F#

Don't you still have to link externally to third party libs since 99% of JS libs won't pass through the closure compiler?

Depends on how you have your project setup. You don't have to pass them through the closure compiler. That's a choice.

Applications are open for YC Summer 2019

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