News for hackers. Stuff that matters.
Re:A History of Clojure [pdf] by enitihas on Thursday June 04, 2020 @03:46PM (#23420920)
> and think it is better than golang's implementation.

How is core.async better than the golang implementation. In golang, all network I/O you do is automatically asynchronous, so your goroutines won't block a thread on network I/O. That is simply something core.async can't do.

Re:A History of Clojure [pdf] by patrickthebold on Thursday June 04, 2020 @05:23PM (#23421989)
I don't know if it does, but why couldn't it? The Java has non blocking IO.
Re:A History of Clojure [pdf] by lenkite on Thursday June 04, 2020 @09:54PM (#23424227)
It's not just a matter of non-blocking IO. core.async uses heavy-weight threads. Go-lang uses light-weight go-routines.

The JVM also would need to incorporate a lightweight process scheduler that can wait on I/O and schedule j-routines when I/O is blocked.

Re:A History of Clojure [pdf] by Skinney on Friday June 05, 2020 @02:21AM (#23425601)
`core.async` does M:N scheduling where many go-blocks are scheduled across a smaller number of heavy-weight threads. `core.async` also has channels and select. It pretty much works the same as in go.

However, since the default in JVM is heavy threads and blocking behaviour, extra care needs to be taken to avoid blocking a thread that a go-block is executing on (as that would also block many other go-blocks).

So it's definitely easier in Go, since you don't need to juggle these two contexts.

JVM has NIO, which provides non-blocking IO. You can use this with core.aysnc's channels to resume a go-block. You have all the pieces you need to write a go-scale clojure service.

Re:A History of Clojure [pdf] by lenkite on Friday June 05, 2020 @05:26AM (#23426568)
Sorry, I completely disagree. I don't consider mere M:N thread work distribution as anywhere close to what the go scheduler offers.

This article mentions some of the fundamental problems with core.async: http://danboykis.com/posts/things-i-wish-i-knew-about-core-a...

Having to pay ridiculously careful attention to what code blocks across libraries and function boundaries is something that golang completely takes away the need for - because it has a true cooperating scheduler built into the runtime at the boundary of every syscall.

Decision making is in hands of the Go runtime. You can write in standard dumb sync fashion at 3am in the night within a go-routine making all the Go library calls you wish to make without needing to scan code with a microscope to see what blocks and what doesn't.

https://www.ardanlabs.com/blog/2018/08/scheduling-in-go-part...

core.async is a half-baked error prone solution. People will make mistakes with it. Until the JVM has native support for fibers, continuations and a compile mechanism to classify all legacy blocking calls as unsafe, core.async will continue to be hobbled.

Re:A History of Clojure [pdf] by Skinney on Friday June 05, 2020 @06:11AM (#23426863)
M:N thread distribution is exactly what the go _scheduler_ offers. It's a work stealing scheduler like Java's ForkJoinPool.

The benefit lies entirely in that there's no other way to do concurrency. Which is great, as it's less error prone. But if you were to introduce native threads in Go you'd have the exact same problems as you'd have with core.async. So it's not like core.async (or async/await in other languages for that matter) is half-baked or badly implemented, but it won't automatically remove a part of the Java runtime that has existed since the beginning.

In a similar vain, Rust's actix and Java's Akka are not half-baked or bad implementations of the actor system, but it is more error-prone to use compared to languages built entirely around the actor paradigm, like Erlang and Pony.

So no, core.async doesn't magically give you non-blocking concurrency, but it does enable it. And that is a much better option than re-writing your entire codebase in Go.

> core.async is a half-baked error prone solution. People will make mistakes with it. Until the JVM has native support for fibers, continuations and a compile mechanism to classify all legacy blocking calls as unsafe, core.async will continue to be hobbled.

With Loom it won't be necessary to add a compile mechanism to classify legacy blocking calls, as there won't be any. This is why Loom is taking so long, the entire runtime is being re-written to not block if IO is performed in a virtual thread, but work as before if a full thread is being used.

And when you can simply create virtual threads instead of native ones, there's really not much value in core.async anymore (well, ClojureScript will still benefit) as Clojure already has great primitives for working with threads.

Re:A History of Clojure [pdf] by gavinray on Thursday June 04, 2020 @10:14PM (#23424338)
I don't know anything about the JVM and my experience with JVM-based languages is incredibly limited, but isn't that the essence of the Loom Project?

https://developers.redhat.com/blog/2019/06/19/project-loom-l...

https://cr.openjdk.java.net/~rpressler/loom/Loom-Proposal.ht...

Re:A History of Clojure [pdf] by lenkite on Thursday June 04, 2020 @11:05PM (#23424646)
Yes, however, the Loom project is still some years away and the Java standard library will need to be extensively revamped to support this. I see this easily a decade in the future.
Re:A History of Clojure [pdf] by Skinney on Friday June 05, 2020 @02:24AM (#23425615)
They have been rewamping the Java standard library slowly and silently over the last couple of years in anticipation for Loom. With Java 14 they re-wrote the tcp socket class. In Java 15 they're re-implementing the udp socket class. These re-implementations are being done to support loom seamlessly in a future update.

They also collaborated with IntelliJ to find bugs related to debugging Java apps, to make sure Loom doesn't break anything there.

Loom is well underway. I wouldn't be surprised if we saw Loom in Java 19 or 20. So in 2-3 years.

Re:A History of Clojure [pdf] by mping on Friday June 05, 2020 @05:55AM (#23426754)
Hell, I just used loom last night on some pet projects. You can use it today if you dare.
Re:A History of Clojure [pdf] by puredanger on Friday June 05, 2020 @02:42AM (#23425720)
The next LTS version of Java is planneed to to be Java 21 (fall 2021, numbers a coincidence) and my presumption is they are trying to get it into that.