News for hackers. Stuff that matters.
Re:Java 21 makes me like Java again by kaba0 on Sunday September 17, 2023 @02:24AM (#37542084)
You can’t decide language superiority by the number of features. While C# indeed has many cool features, I do think it has already went into C++ territory where all the different, independently cool features have very non-trivial interactions that make it very hard to reason about.

Also, async-await is not a good thing — virtual threads are superior in every way in case of a managed language.

Re:Java 21 makes me like Java again by neonsunset on Sunday September 17, 2023 @03:27AM (#37542420)
Why async/await is not a good thing? What makes green threads better? Do you know the difference, the issues async/await addresses that green threads simply do not?
Re:Java 21 makes me like Java again by pjmlp on Sunday September 17, 2023 @03:45AM (#37542524)
Read David Fowler's guidelines.
Re:Java 21 makes me like Java again by winter_blue on Sunday September 17, 2023 @06:00AM (#37543319)
Do you have link to any specific article of his (on virtual threads vs async)?
Re:Java 21 makes me like Java again by pjmlp on Sunday September 17, 2023 @07:15AM (#37543785)
Re:Java 21 makes me like Java again by kamma4434 on Sunday September 17, 2023 @04:47AM (#37542900)
Because they were created to manually run multiple threads on one physical thread, which is the kind of decoupling that a VM/OS is supposed to do for you.
Re:Java 21 makes me like Java again by tomp on Sunday September 17, 2023 @09:22AM (#37544805)
This is code with async/await:

  async fn read_file(filename):
    f = await os.open(filename)
    let data = f.read()
    await f.close()
    return data
this is equivalent code with green threads:

  fn read_file(filename):
    f = os.open(filename)
    let data = f.read()
    f.close()
    return data
As you can see, async/await is pure syntactic noise, it doesn't convey any important meaning.
Re:Java 21 makes me like Java again by neonsunset on Sunday September 17, 2023 @09:25AM (#37544831)
Async enables clear contract for a type that represents a delayed result.

Better implementations offer eager execution and allow to easily interleave multiple concurrent futures/tasks, like C#. Green threads on the other hand are a workaround to deal with blocking for the most trivial case of cooperative multi-tasking, offering little beyond that.

Re:Java 21 makes me like Java again by kaba0 on Sunday September 17, 2023 @09:38AM (#37544953)
> Async enables clear contract for a type that represents a delayed result.

It's not really a type, otherwise it would be something like Future<T> in Java and plenty other languages. It is usually implemented as a transformation to a state machine.

Also, Loom is M:N and calling them green threads doesn't give you the whole picture at all. Not exactly sure what you mean by easily interleave -- functionality wise the two is more or less equivalent. You just get to keep your simpler mental model (and tooling) with virtual threads.

Re:Java 21 makes me like Java again by tomp on Sunday September 17, 2023 @10:51AM (#37545614)
with green threads, every result is "delayed" and available exactly when you want it (i.e. as indicated by naive reading of the control flow in code)

> eager execution, interleave multiple concurrent tasks

green threads give you that for free

> deal with blocking

blocking is an implementation detail; both async/await and green threads can be implemented on top of either traditional blocking IO, or callback/non-blocking IO

I'd be even happier to discuss concrete code blocks / examples, that's where the superiority of green threads truly shines

Re:Java 21 makes me like Java again by ncruces on Sunday September 17, 2023 @11:24AM (#37546021)