Re:Java 20 Is Out!
by hn_throwaway_99 on Tuesday March 21, 2023 @01:27PM
(#35249444)
All of your examples basically map to Javascript destructuring, which is already fully supported. Comment you are replying to is asking about pattern matching for flow control or conditional assignment, which JS doesn't currently support.
Re:Java 20 Is Out!
by satvikpendem on Tuesday March 21, 2023 @01:31PM
(#35249502)
Is Dart's pattern matching influencing the JS proposal as well? Or are both sort of separate without much influence from either side?
Re:Java 20 Is Out!
by munificent on Tuesday March 21, 2023 @01:49PM
(#35249772)
I have read the JS proposal many times, so it's an influence on Dart. I suspect Dart hasn't had much influence on JS because our proposal is newer.
> the "matching" part means that in many languages you can also ask questions about values as you destructure them,
I started implementing Lox with Java's sealed classes + pattern matching on switch. The exhaustiveness has been really nice to ensure I cover each new token/expression as I add them.
Pattern matching parallels that, except for assignment and decomposing values. Many languages today let you write:
Or even: (Because at least you can compose expressions on the RHS.) But they don't let you write: Or even: Pattern matching gives you that. It is freely composable destructuring.Also, the "matching" part means that in many languages you can also ask questions about values as you destructure them, which enables a particularly nice style of programming.