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 full-size slide

  2. Let's talk about JavaScript

    View full-size slide

  3. '' == 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 full-size slide

  4. Built with JS
    desktop apps

    View full-size slide

  5. Built with JS
    mobile apps

    View full-size slide

  6. Built with JS
    backends

    View full-size slide

  7. Oh, right, and the

    View full-size slide

  8. It matters
    (like it or not)

    View full-size slide

  9. Mythical Trees
    and where to find them

    View full-size slide

  10. AST Explorer

    View full-size slide

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

    View full-size slide

  12. downsides
    4 loading time
    4 extra infra

    View full-size slide

  13. Write a parser from scratch

    View full-size slide

  14. Benefits
    4
    !
    fast
    4

    no extra infra
    demo

    View full-size slide

  15. Fast forward a few weeks

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  19. 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 full-size slide