News for hackers. Stuff that matters.
Re:Java 21 Released by lambda_garden on Tuesday September 19, 2023 @11:28AM (#37571334)
Java 21 is colorblind - but the colors still exist
Re:Java 21 Released by lolinder on Tuesday September 19, 2023 @11:30AM (#37571370)
Yep, I agree. I tend to be a type system maximalist: I'd rather have everything that is possible to encode statically be encoded statically, even if it leads to less flexibility later.

If you're starting a new Java codebase from scratch, you can create the structure where the language doesn't using classes, but it'd be nice to have syntactic support for it.

Re:Java 21 Released by kaba0 on Tuesday September 19, 2023 @11:37AM (#37571469)
This property is not really part of the type system though.

Also, as mentioned by another commenter below - is a file exists operation async? Sync? Why, why not?

Re:Java 21 Released by wiseowise on Tuesday September 19, 2023 @11:51AM (#37571747)
What if file exists operation MUST be sync?
Re:Java 21 Released by kaba0 on Tuesday September 19, 2023 @11:57AM (#37571855)
Then you don’t start it in a virtual thread. Your calls automatically become blocking or not blocking depending on your callsites, which is the proper place to decide that.
Re:Java 21 Released by wiseowise on Tuesday September 19, 2023 @11:59AM (#37571880)
So it still has colors?
Re:Java 21 Released by lolinder on Tuesday September 19, 2023 @11:56AM (#37571828)
In TypeScript at least, async-ness is encoded in the type system, because async/await is just syntactic sugar for Promise/then/catch.
Re:Java 21 Released by kaba0 on Tuesday September 19, 2023 @12:42PM (#37572565)
Well, JS is paired with a single-threaded execution model, so you only have concurrency to worry about. C#, Java has proper multithreading as well, that gives another dimension to the problem.
Re:Java 21 Released by lolinder on Tuesday September 19, 2023 @01:27PM (#37573231)
Kotlin has multithreading, and it also puts `suspend` in the type system.
Re:Java 21 Released by n2d4 on Tuesday September 19, 2023 @02:56PM (#37574590)
Some more examples: Rust, Python (with most/all? type checkers), C# all bake this into their type systems.
Re:Java 21 Released by vips7L on Tuesday September 19, 2023 @05:02PM (#37576589)
This is more due to the fact that Kotlin doesn’t control its backend and is designed to work with a language that already includes this model, js.
Re:Java 21 Released by samus on Tuesday September 19, 2023 @08:26PM (#37578946)
Very simple - in Java, almost any IO operation in blocking. Exceptions are the stuff in the NIO package, thread interruption and signalling, and maybe process termination.
Re:Java 21 Released by jayd16 on Tuesday September 19, 2023 @11:37AM (#37571475)
I wonder if we'll see Lombok markup for @OnVirtualThread or whatever the pattern shakes out to be.
Re:Java 21 Released by andrewaylett on Tuesday September 19, 2023 @11:57AM (#37571842)
Lombok is unfortunately a separate programming language, albeit insufficiently distinct from Java.

(Why? Because it uses internal compiler APIs to change the behaviour of code you write in ways that are not valid: annotation processors are supposed to generate new classes, not mutate existing classes.)

Re:Java 21 Released by samus on Tuesday September 19, 2023 @08:30PM (#37578981)
I went looking on their because for some reason I thought that an `@Async` annotation would already exist. But no such luck.

If you want to use something like this today, then you could take a look at Spring 's Async support. It also lets you supply the Executor.