News for hackers. Stuff that matters.
Re:Java Is in Decline, and There's Data to Prove It by bennysonething on Sunday January 01, 2023 @09:08AM (#34206341)
I primarily write c# for a living. What's wrong with async await in kotlin? I'd struggle to live without it in c#.
Re:Java Is in Decline, and There's Data to Prove It by nlitened on Sunday January 01, 2023 @09:13AM (#34206378)
Async/await is extra syntax and one more function color which you have to keep in mind, while being just a workaround for expensive threads.

Recent Java has just made threads cheap, so async concurrency is much simpler and more consistent with existing libraries and APIs.

Re:Java Is in Decline, and There's Data to Prove It by joe_fishfish on Sunday January 01, 2023 @09:34AM (#34206535)
Cheap threads are fine if you’re in a server environment, and you need to spin up a large number of short lived parallel jobs.

It’s not hugely helpful for a UI-bound application which occasionally needs to move some work into a background thread to cut down on UI jank.

Kotlin’s suspending function syntax effectively lets you know which operations are going to (potentially) take a while, so you can make sure the UI thread isn’t blocked, and also make sure you’re communicating to the user that something is happening.

Re:Java Is in Decline, and There's Data to Prove It by kasperni on Sunday January 01, 2023 @11:12AM (#34207493)
Custom schedulers are coming later with Project Loom. Should be fairly easy to create something where particular threads could have a higher/lower priority.
Re:Java Is in Decline, and There's Data to Prove It by nlitened on Sunday January 01, 2023 @01:10PM (#34208903)
If I understand your point correctly, you say that suspend keyword gives you a hint for which functions are long running, so that you run them in a background thread.

I think that’s a very flawed assumption. Some IO operations are pretty fast, like reading a local filesystem, and can be done in the UI thread, while some heavy non-async functions are accidentally O(n^2), and freeze your IO thread.

And if you say that “of course you should know what you’re doing”, then I think that suspend syntax just adds extra complexity without much semantic benefit.

Re:Java Is in Decline, and There's Data to Prove It by invalidname on Sunday January 01, 2023 @01:47PM (#34209338)
Loom has zero impact on client, sure. But I disagree that async is better for client. It makes it much harder to debug and track issues.
Re:Java Is in Decline, and There's Data to Prove It by pharmakom on Sunday January 01, 2023 @09:23AM (#34206456)
An Async<T> is not a T whether you have the monadic sugar or not.

Why make life more difficult when you can have code that reads linearly?

Re:Java Is in Decline, and There's Data to Prove It by wiseowise on Monday January 02, 2023 @09:08AM (#34217945)
In Kotlin it is just T, the function is suspend.
Re:Java Is in Decline, and There's Data to Prove It by pharmakom on Monday January 02, 2023 @11:06AM (#34219442)
Then the language is implicitly converting it through suspension for you. They are still different things. What if you don’t want that to happen?
Re:Java Is in Decline, and There's Data to Prove It by tluyben2 on Sunday January 01, 2023 @09:43AM (#34206599)
Can you provide a good cheap thread example for Java vs async/await. What I find online is horrible compared to async/await but people keep talking about function colouring etc. I just cannot see what is the issue. Nor do people give better examples; I was watching some guy on YouTube who said async/await sucks and my idea is better, then spent 30 minutes explaining his idea vaguely. No implementation, no examples.
Re:Java Is in Decline, and There's Data to Prove It by nlitened on Sunday January 01, 2023 @12:50PM (#34208692)
In the simplest case, you take an async function, remove `async` and `await` keywords, and as a result you get a normal function which you can call and get a result without awaiting, which has better and more predictable performance, and a straightforward stack trace (and a simpler language syntax and semantics). All upsides, no downsides.

Probably you can think of a more complex example where it’s not that straightforward, please link code that you have in mind, we can see how with cheap threads it could be made better.

Re:Java Is in Decline, and There's Data to Prove It by pulse7 on Sunday January 01, 2023 @09:09AM (#34206349)
Function coloring
Re:Java Is in Decline, and There's Data to Prove It by andix on Sunday January 01, 2023 @09:17AM (#34206399)
Async/await doesn’t change anything there. It just makes it easier to deal with.
Re:Java Is in Decline, and There's Data to Prove It by justoreply on Sunday January 01, 2023 @10:34AM (#34207088)
With the new thread model in java (project Loom) you don't need function coloring
Re:Java Is in Decline, and There's Data to Prove It by andix on Monday January 02, 2023 @10:04AM (#34218608)
I don't know the details. But a synchronous function returns a value and an async function returns something promise-like (it completes at some point and returns a value or an error).

You can always call something async synchronously (by waiting for finishing). Or something synchronous in an async way (by putting it onto another thread). But there is no way to completely remove this fact from the eyes of the programmer. async/await is one of the ways to make it easier to read or write.