Scala.js for large and complex front end apps [video]
youtube.com
youtube.com
I honestly wish I could use Scala in the browser. I'm using Typescript instead. The compilation down to ES6 is so trivial that I don't have to try to guess what the compiler is doing. I can read javascript code and documentation and almost never have trouble figuring out how I would write the same thing in TS. I get the primary benefit of static types, even though I don't get all of the ADT and pattern matching goodness. IDE support in Atom is excellent. Compilation is fast. And the community is large enough that I can usually find an answer quickly through the normal SO, IRC, email list channels.
My impression is that the quality of tools in the JS world is so damn low, that they're more of a hindrance than help. Gluing together Grunt, Sass, Bower, NPM, Browserify, Uglify and a bunch of internal libraries was a titanic task.
By contrast, in the Scala world tools are easier to reason about, fail more cleanly and usually surface problems at compile/build time.
And yes, the js tools are loathsome in general. I've found Typescript to be the best tool available to me, and webpack is pretty good as well. Everything else I've been able to cut out thankfully.
Anyway, I hear you, although the only way to make Scala.js work better for everyone is to use it. Otherwise building a community is an insurmountable chicken-and-egg problem.
Yes, you have to be familiar with the underlying platform. This is also true for languages running on top of the JVM, as you have to be familiar with the JVM and Java's ecosystem and with POSIX and with the target operating system and so on. And that's not just for Scala and the JVM. Don't get me wrong, you don't have to be an expert, but some knowledge of your underlying stack is always required.
> Having a problem with the scala version of the react library you want to use? Write up a question for stack overflow, post an issue on github, and then hunker down in the source code and try to find the answer on your own while waiting a few days for a response.
Isn't that, you know, how programming works? Yes, you end up interacting with other people through GitHub Issues, Gitter/IRC channels, StackOverflow, etc. It's actually rewarding, because you end up learning a lot. Us developers, we tend to be introverts. It's hurting us ;-)
> The compilation down to ES6 is so trivial that I don't have to try to guess what the compiler is doing.
It also means that Typescript is barely a step up from Javascript, so why bother? If you're going to be hip and choose an option that isn't THE mainstream choice, don't you want to pick something that brings enough benefits, to counter-balance the disadvantages of not going for straight Javascript?
Scala is a statically typed language in a way that Typescript will never be. Scala enables functional programming in a way that Typescript will never do. For all the bitching and moaning about Scala's SBT build tool and Maven's repositories, it's light years beyond the clusterfuck in Javascript's land when it comes to build tools, continuous integration and dependencies management.
And the best part of Scala.js is that you get to use many Scala libraries that are now cross-compiled. That means for example many of the Typelevel libraries, like Simulacrum, Cats, Shapeless, Spire and as a shameless plug, my own Monix: https://github.com/monixio/monix/
Scala's ecosystem isn't huge, like that of Java or Javascript, but you know, libraries tend to be in much better shape. For example Scala always had good Future implementations (again, versus the clusterfuck that happened in Javascript) and now Scala has Scala-Async which gives you async/await keywords without having to sacrifice browser compatibility: https://github.com/scala/async
Have a problem with React? Fix it. That's how you and the community can grow.
That's not how things work in the real world and you know it. Furthermore if you're good enough to fix React then you're good enough to write a complicated JS codebase without the need for a third party language.
> It also means that Typescript is barely a step up from Javascript
Typescript is a huge step up from Javascript has it brings type safety, which eliminates a whole class of errors, make the code easier to read and document and the price to pay for using TS is quite low compared to using Scala.js .
Scala has its place, but right now it's definitely not in the front-end.
I'd agree with the other commenters that it makes a lot less sense if you are hiring outside front end devs. You'd probably have a lot less friction if you stick to something more mainstream - either pure Javascript or maybe typescript.
Since my project (https://invotes.com) is a one man operation written purely in Scala at this point, I've used Scala.js on the front end with great results. It's nice to be able to cross compile common functionality between the server, frontend, and Android. I haven't run into any blocking issues between the three platforms. It's also pretty straightforward. I hadn't used Scala at all prior to this project, but most everything makes sense (and I don't even have a problem with SBT).
The biggest downside is the increase in JS size, but at this point it's not too unexpected to have an overall page size at ~1mb, and at least it's all one minified file once it goes to production.
The response from the front-end guys was mostly not pretty. Over time I've come to realise the cultures are miles apart. Scala devs really value type systems and FP and all its benefits - the JS guys value very different things. The hotchpotchness of tools and frameworks in that world is actually seen as a plus point, as diverse devs collaborating, as some community thing. I will never understand it.
Add time for compiling, edge cases, bugs and no matter how awesome it is, I can't see how it ever makes sense outside of a 1 person project.
[1] Yes, classes. As in: You can never misspell an object property and have that mistake make it into production (&c for lots of other types of bugs). Plus, you get automatic refactoring you can actually rely on. Now, your JS devs may not appreciate that, but I suspect that's just because they're inexperienced and/or haven't actually worked in a good[2] statically typed language. There's also the fact that we (as humans) unconsciously try to minimize our own mistakes; "oh well, it was just a typo and we fixed it quickly!" and for most of us mistakes tend to fade quickly from memory... thus leading to a very biased view of one's own development practices which doesn't take into account how many mistakes you really make.
[2] I'm going to do a D. F. Wallace here[3].
[3] ... and say that Scala isn't great as languages go[5], but I'll bet you it's a hell of a lot better than any statically typed language your typical JS devs have any experience with[4]. One particular gripe of mine is that they still permit "null", but that's because of Java compatibility. (Oh, how much better Scala could have been without Java compatibility.)
[4] ... which would obviously colour their perception of the trade-offs between static type checking and "verbosity", "bondage & discipline", etc.
[5] It is good, though.
I think that's enough footnotes for now.
EDIT: Sorry, I lied. Added another footnote. Really doing the DFW thing, but in Reel Time(TM).
[1] My company started out with TS, but after converting about 10% of our app from TS to Scala.JS + scala.js-react we just decided to convert the rest in a mad sprint over a few weeks. It has paid off in spades. We still struggle with the abomination that is CSS and separating styles from components, but it is what it is.
(It seems subtyping and higher-order reasoning just don't mix well. Undecidability abounds, unfortunately. I tend to prefer higher-order reasoning over subtyping.)
I would look at Elm as if it compiles you will not get a runtime error but Elm devs probably are even more scarce then Scala devs.
Scala.js solved all the problems you mention.
* Performance is on par with hand-written JavaScript.
* The compiler and optimizer are incremental so they compile your code in 1-2 seconds for significant codebases.
* Interoperability is as easy as in TypeScript: just use type definitions for external JS libraries and then transparently call them.
It's all explained from the big boxes on the page of https://www.scala-js.org/
Don't let your past experiences give you wrong impression of Scala.js.
NOPE. Was on an all FE team. The one BE guy embedded with our team got it, the FE devs just looked at me with blank stares during my presentation.