> structured concurrency That's another huge effort which delivered us an imperfect abstraction. I would prefer to have HKTs and typeclasses, so I may implement my own IO monad.
> I would prefer to have HKTs and typeclasses, so I may implement my own IO monad. I'm not a Java developer, and I haven't even read about higher kinded types or typeclasses (the theory side of programming is my weakness); but you picked my curiosity with this. Can you elaborate how concurrency done this way would look in Java?
Java 20 / JDK 20: General Availability
51–60 of 356 posts
Re: Java 20 / JDK 20: General Availability
#52Re: Java 20 / JDK 20: General Availability
#53Re: Java 20 / JDK 20: General Availability
#54This is exciting, can't wait for the LTS release next year... that said, I don't much care for the "case SomeType t when ..." pattern matching syntax, I don't see the benefit of introducing a new keyword over using "if"... or even just "&&". To pinch the example used in[1]: case Tuner t && guitar.isInTune() -> ...; and case Tuner t if guitar.isInTune() -> ...; both seem as clear as case Tuner t when guitar.isInTune()…
The “&&” one is bizarre, it makes it look like the whole thing is a Boolean expression, which it absolutely is not. That gets even weirder because the part right of it actually is a Boolean expression, so on top of very confusing reading you now make it look like there are strange interactions with operator precedence. Using && is one of the worst choices. The “if” one does not suffer from any such problem and reads…
Given this pattern matching syntax change, you'd write:
switch(obj) {
case Tuner t when guitar.isInTune() -> ...;
...
}
For a switch, but for an if statement it's written as: if (obj instanceof Tuner t && guitar.isInTune()) {
...
}
Edit: I do wonder, actually, if avoiding "&&" is to allow the "when" case execution to be reordered (e.g. to allow JIT to extract common "when" conditions prior to the switch expression), which would be wrong to do given the short-circuiting rule implications of "&&"Re: Java 20 / JDK 20: General Availability
#55Re: Java 20 / JDK 20: General Availability
#56Now even Java has pattern matching, what's Javascript's excuse? Literally the only feature preventing Typescript from being my perfect language.
https://github.com/tc39/proposal-pattern-matching I'm not sure if it's stalled or not. But it's being discussed.
Re: Java 20 / JDK 20: General Availability
#57This is exciting, can't wait for the LTS release next year... that said, I don't much care for the "case SomeType t when ..." pattern matching syntax, I don't see the benefit of introducing a new keyword over using "if"... or even just "&&". To pinch the example used in[1]: case Tuner t && guitar.isInTune() -> ...; and case Tuner t if guitar.isInTune() -> ...; both seem as clear as case Tuner t when guitar.isInTune()…
This year. Six months from today.
https://en.wikipedia.org/wiki/Java_version_history
The non-LTS releases are every 6 months and have support for one year.
LTS releases are every 4th release which falls on odd numbered years in September.
Re: Java 20 / JDK 20: General Availability
#58Now even Java has pattern matching, what's Javascript's excuse? Literally the only feature preventing Typescript from being my perfect language.
Not to mention JS is not typed, but pattern matching that can't match typescript types would be terrible.
Re: Java 20 / JDK 20: General Availability
#59This is exciting, can't wait for the LTS release next year... that said, I don't much care for the "case SomeType t when ..." pattern matching syntax, I don't see the benefit of introducing a new keyword over using "if"... or even just "&&". To pinch the example used in[1]: case Tuner t && guitar.isInTune() -> ...; and case Tuner t if guitar.isInTune() -> ...; both seem as clear as case Tuner t when guitar.isInTune()…
The “&&” one is bizarre, it makes it look like the whole thing is a Boolean expression, which it absolutely is not. That gets even weirder because the part right of it actually is a Boolean expression, so on top of very confusing reading you now make it look like there are strange interactions with operator precedence. Using && is one of the worst choices. The “if” one does not suffer from any such problem and reads…
FWIW, though, I don't find it "bizarre". While it's not a boolean expression per Java, at least in my mind it serves the same purpose: "in the case that thing x is of type SomeType and ...some other thing about ((SomeType)x) is true...".
I think it's a tough choice, I'm sure they were probably not wanting to add a new keyword, but at the end of the day "when" is so familiar to anyone who's ever written SQL (which I'm guessing is most Java devs) so seems like a good choice.
Re: Java 20 / JDK 20: General Availability
#60Earlier quoted context omitted.
The “&&” one is bizarre, it makes it look like the whole thing is a Boolean expression, which it absolutely is not. That gets even weirder because the part right of it actually is a Boolean expression, so on top of very confusing reading you now make it look like there are strange interactions with operator precedence. Using && is one of the worst choices. The “if” one does not suffer from any such problem and reads…
I'm not a Java user, but I really don't love the overloading of `if` in Python (statement, ternary, comprehensions), so introducing a new keyword here seems pretty reasonable to me. And don't even get me started on `static` in C++.