Live data from Hacker News

Java 20 / JDK 20: General Availability

mail.openjdk.org

41–50 of 356 posts

Re: Java 20 / JDK 20: General Availability

#42

> 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?

Re: Java 20 / JDK 20: General Availability

#43
post #2

Gist: ``` JDK 20 introduces six features: - Scoped values for safe sharing of data across threads - Record patterns for declarative data navigation and processing - Foreign function and memory API for interoperation with code and data outside the Java runtime - Virtual threads for lightweight concurrent programming - Structured concurrency for simplified multithreaded programming - Pattern matching for switch stateme…

...but also thousands of other stability, performance, and security updates.

Don't worry, someone will still manage put in a bug that results in a zero day in the next 2 years.

Re: Java 20 / JDK 20: General Availability

#45
post #34

This 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…

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++.

Re: Java 20 / JDK 20: General Availability

#46

This 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.

Re: Java 20 / JDK 20: General Availability

#49

This 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()…

I think the only reason is that they're very different, if you define them:

    type when expression -> block

    if expression -> block
For parsing works better, for programmers is better since they don't confuse both concepts, and in general pattern matching isn't the same as a if condition or a switch.

https://stackoverflow.com/questions/199918/explaining-patter...

I think the difference is when you start pattern matching on tuples and other types that you cannot do a simple `if ident.isinstanceof(type) ->`.

For example in Elixir you can do:

    def ident(param = {:key => true}):
This will only match when the param type is not only `map`, but also contains a key named `:key` and its value is `true`.

In the end though, it's syntax sugar (but everything is if you put it that way classes are syntax sugar).

Post reply on HN