Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Bridging the tooling gap with Scala.js

Bridging the tooling gap with Scala.js

Scala.js is a tool for compiling your Scala code to JavaScript. This enables writing type-safe and robust front-end application, but have you ever considered what it can do for Scala tooling? In this talk we’ll see how Scala.js can bridge the gap between the Scala-based and the JavaScript-based tools we use every day as programmers.

Gabriele Petronella

April 16, 2018
Tweet

More Decks by Gabriele Petronella

Other Decks in Programming

Transcript

  1. Bridging the
    tooling gap
    with Scala.js

    View Slide

  2. me, hi!

    View Slide

  3. stuff I do

    View Slide

  4. Let's talk about JavaScript

    View Slide

  5. '' == false // true
    [''] == '' // true
    [[]] == 0 // true
    typeof document.all // undefined
    document.all === undefined // false
    document.all === null // false
    document.all == null // true
    Number.MIN_VALUE > 0 // true
    ['1','2','3'].map(parseInt) // [1, NaN, NaN]

    View Slide

  6. Built with JS
    desktop apps

    View Slide

  7. Built with JS
    mobile apps

    View Slide

  8. Built with JS
    backends

    View Slide

  9. Oh, right, and the

    View Slide

  10. It matters
    (like it or not)

    View Slide

  11. A story

    View Slide

  12. Mythical Trees
    and where to find them

    View Slide

  13. AST Explorer

    View Slide

  14. View Slide

  15. First idea
    +-------------------------+ +------------------------+
    | | | |
    | | | |
    | | | |
    | | source | |
    | +---------------------------------------> | |
    | | | |
    | | | |
    | | | |
    | AST EXPLORER | | JVM SERVER |
    | | | |
    | | AST | (SCALAMETA) |
    | | <---------------------------------------+ |
    | | | |
    | | | |
    | | | |
    | | | |
    | | | |
    | | | |
    | | | |
    | | | |
    +-------------------------+ +------------------------+

    View Slide

  16. downsides
    4 loading time
    4 extra infra

    View Slide

  17. Write a parser from scratch

    View Slide

  18. Scala.js?

    View Slide

  19. Scala.js!

    View Slide

  20. View Slide

  21. Benefits
    4
    !
    fast
    4

    no extra infra
    demo

    View Slide

  22. Fast forward a few weeks

    View Slide

  23. View Slide

  24. First idea
    +-------------------------+ +------------------------+
    | | | |
    | | | |
    | | | |
    | | source | |
    | +---------------------------------------> | |
    | | | |
    | | | |
    | | | |
    | VSCODE | | SCALAFMT CLI |
    | | | |
    | | formatted source | (JVM) |
    | | <---------------------------------------+ |
    | | | |
    | | | |
    | | | |
    | | | |
    | | | |
    | | | |
    | | | |
    | | | |
    +-------------------------+ +------------------------+

    View Slide

  25. Downsides
    4
    !
    slow (for a single file)
    4
    "
    not self-contained

    View Slide

  26. Scala.js?

    View Slide

  27. Yep

    View Slide

  28. Upsides
    4
    !
    fast
    4
    "
    self-contained
    Downsides
    4
    !
    config -> cross-platform HOCON is still meh

    View Slide

  29. Free ideas, grab them!
    4 scalafmt on astexplorer.net
    4 (alternatively) standalone playground on
    scalafmt.org
    4 browser extension that formats code comments
    4 scalafmt on scala native
    4 GitHub app for scalafmt checks (talk to
    @laughedelic)

    View Slide

  30. Thanks

    View Slide