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

Scala 3 - A Quick Tour - Scala Italy 2021

Scala 3 - A Quick Tour - Scala Italy 2021

Daniela Sfregola

October 23, 2021
Tweet

More Decks by Daniela Sfregola

Other Decks in Programming

Transcript

  1. Scala 3


    A Quick Tour


    @DanielaSfregola


    Scala Italy - October 2021

    View Slide

  2. Hellooooo
    • Software Engineer 

    living in London UK

    • Scala Lover ❤

    • OS Maintainer

    • Author of 

    "Get Programming with Scala"
    by Manning


    35% OFF on EVERYTHING

    with code "ctwscalait21"

    View Slide

  3. Scala 3 is here!
    • After 8 years of work

    • 28,000 commits

    • 7,400 pull requests

    • 4,100 closed issues

    • ...released on May 13th, 2021!
    https://www.scala-lang.org/blog/2021/05/14/scala3-is-here.html

    View Slide

  4. An overview
    • https://dotty.ep
    fl
    .ch/docs/reference/overview.html

    View Slide

  5. @main Annotation
    object HelloWorld extends App
    {

    println("Hello World!"
    )

    }

    View Slide

  6. @main Annotation
    object HelloWorld extends App
    {

    println("Hello World!"
    )

    }

    object HelloWorld
    {

    @main def hello: Unit =
    {

    println("Hello world!"
    )

    }

    }

    View Slide

  7. @main Annotation
    object HelloWorld extends App
    {

    println("Hello World!"
    )

    }

    object HelloWorld
    {

    @main def hello: Unit =
    {

    println("Hello world!"
    )

    }

    }

    object Hello
    {

    @main def echo(n: Int, word: String): Unit =
    {

    println(word * n
    )

    }

    }

    View Slide

  8. Parametrized Traits
    trait Nameable
    {

    def name: Strin
    g

    }

    View Slide

  9. Parametrized Traits
    trait Nameable
    {

    def name: Strin
    g

    }

    trait Nameable(name: String)

    View Slide

  10. Intersection Types
    class
    A

    class
    B

    def foo: A & B = ???

    View Slide

  11. Union Types
    class
    A

    class
    B

    def foo: A | B = ???

    View Slide

  12. Package Object
    // in file my/demo/package.scal
    a

    package m
    y

    package object demo
    {

    def customLog(msg: String)
    {

    println(s"Customised package log: $msg"
    )

    }

    }

    View Slide

  13. Package Object
    // in file my/demo/package.scal
    a

    package m
    y

    package object demo
    {

    def customLog(msg: String)
    {

    println(s"Customised package log: $msg"
    )

    }

    }

    [ DROPPED ]

    View Slide

  14. Enums
    sealed abstract class Color(val rgb: Int)

    case object Red extends Color(0xFF0000
    )

    case object Green extends Color(0x00FF00
    )

    case object Blue extends Color(0x0000FF)

    View Slide

  15. Enums
    sealed abstract class Color(val rgb: Int)

    case object Red extends Color(0xFF0000
    )

    case object Green extends Color(0x00FF00
    )

    case object Blue extends Color(0x0000FF)
    enum Color(val rgb: Int)
    :

    case Red extends Color(0xFF0000
    )

    case Green extends Color(0x00FF00
    )

    case Blue extends Color(0x0000FF)

    View Slide

  16. Improved Type Inference
    Map("Scala" -> 3).map { (k, v) => s"$k$v" }

    View Slide

  17. Improved Type Inference
    Map("Scala" -> 3).map { (k, v) => s"$k$v" }
    Scala 2.13.4

    View Slide

  18. Improved Type Inference
    Map("Scala" -> 3).map { (k, v) => s"$k$v" }
    Scala 2.13.4

    View Slide

  19. Improved Type Inference
    Map("Scala" -> 3).map { (k, v) => s"$k$v" }
    Scala 3.0.0

    View Slide

  20. Improved Type Inference
    Map("Scala" -> 3).map { (k, v) => s"$k$v" }
    Scala 3.0.0
    Scala 2.13.4

    View Slide

  21. Procedure Syntax
    def echo(str: String)
    {

    st
    r

    }

    View Slide

  22. Procedure Syntax
    def echo(str: String)
    {

    st
    r

    }
    Scala 2.13.4

    View Slide

  23. Procedure Syntax
    def echo(str: String)
    {

    st
    r

    }
    Scala 2.13.4

    View Slide

  24. Procedure Syntax
    def echo(str: String)
    {

    st
    r

    }
    Scala 3

    View Slide

  25. Procedure Syntax
    def echo(str: String)
    {

    st
    r

    }
    Scala 3

    View Slide

  26. Improved Error Messages
    Arrested Developers
    What the Scala Compiler & Lucille Bluth 

    Have In Common
    by Fiona Condon, NeScala 2017
    https://www.youtube.com/watch?v=78iIbiRwFTM

    View Slide

  27. Improved Error Messages
    def echo(str: String): Unit =
    {

    st
    r

    }

    def echoTwice(str: String): String =
    {

    echo(str) match
    {

    case x: String => s"$x$x
    "

    }

    }

    View Slide

  28. Improved Error Messages
    Scala 2.13.4

    View Slide

  29. Improved Error Messages
    Scala 2.13.4
    Scala 3

    View Slide

  30. Strict Equality
    List("Scala", "3").headOption == "Scala"

    View Slide

  31. Strict Equality
    List("Scala", "3").headOption == "Scala"
    Scala 2.13.4

    View Slide

  32. Strict Equality
    List("Scala", "3").headOption == "Scala"
    Scala 2.13.4
    Scala 3

    View Slide

  33. Compatibility with 2.13
    Migrating to Scala 3
    is easy* !
    * if you are using Scala 2.13
    * if you don't have macros in your code
    Scala 3 Migration Guide
    https://docs.scala-lang.org/scala3/guides/migration

    View Slide

  34. Thank You!
    •Twitter: @DanielaSfregola

    •"Get Programming with Scala" 

    by Manning


    35% OFF on EVERYTHING 

    with code "ctwscalait21"

    View Slide