Remix.run Logo
gedy a day ago

As a former Scala fan, wow you aren't kidding, wth

    val month = i match
        case 1  => "January"
        case 2  => "February"
        // more months here ...
        case 11 => "November"
        case 12 => "December"
        case _  => "Invalid month"  // the default, catch-all
    
    // used for a side effect:
    i match
        case 1 | 3 | 5 | 7 | 9  => println("odd")
        case 2 | 4 | 6 | 8 | 10 => println("even")
    
    // a function written with 'match':
    def isTrueInPerl(a: Matchable): Boolean = a match
        case false | 0 | "" => false
        case _ => true
jfim a day ago | parent | next [-]

It's been a while since I touched Scala but wasn't that a thing in previous versions, minus the braces not being present?

weego a day ago | parent [-]

Yes, that's all just as it was, and in places braces were not required / interchangeable so this is more of an optional compiler choice than a real change

malkia a day ago | parent | prev | next [-]

Sorry, I'm coming from C++-ish background - can anyone explain what's going on :)

hocuspocus a day ago | parent [-]

Scala 2's syntax is mostly Java/C-style with a few peculiarities.

Scala 3's optionally allows indentation based, brace-less syntax. Much closer to the ML family or Python, depending on how you look at it. It does indeed look better, but brings its share of issues.[1] Worse, a lot of people in the community, whether they like it or not, think this was an unnecessary distraction on top of the challenges for the entire ecosystem (libraries, tooling, ...) after Scala 3.0 was released.

- [1] https://alexn.org/blog/2025/10/26/scala-3-no-indent/

gedy a day ago | parent [-]

My personal take is this would be like JavaScript adopting an optional Coffeescript[1] syntax. It's so different that it seems odd to make it an option vs a new language, etc.

[1] https://coffeescript.org/#introduction

bdangubic a day ago | parent | prev [-]

madness :)

a24j a day ago | parent [-]

Can you eli5 the madness? And how that relates to python/java?

a day ago | parent [-]
[deleted]