Hacker News new | ask | show | jobs
by dminik 27 days ago
> Goroutines are a far more tractable primitive for coding agents than threads

Goroutines are literally threads. Yeah, this really is a "go is my fav" article.

3 comments

I use both go and python in my day job. The code that Sonnet produces for Go is much better than the Python it creates.

This could be because our go code is typically smaller more defined services but I don't really believe that since even the isolated python services are pretty spaghetti looking.

Goroutines are not directly equivalent to threads.
If 100 goroutines are handled by 10 threads, the effect on correctness is identical: any two can be running in parallel with each other (not just concurrently). From the point of view of this discussion, that's all that matters.
Correctness is nice but performance characteristics exist too.
They used to not be, because they were cooperatively scheduled and threads can be preempted. But they added goroutine preemption in Go 1.14 so in practice there aren't really any significant differences to threads, at least in semantics. (At least as far as I remember; been a while since I wrote any Go.)

You can be pedantic and say they aren't technically threads but that doesn't really matter from a programming perspective.

Even when goroutines were cooperatively scheduled, because the cooperation was mostly hidden and every function call was a yield point the average developer would treat them as being cooperative... until they spawned too many goroutines with a tight loop (and no function call) and the runtime locked up.

> You can be pedantic and say they aren't technically threads but that doesn't really matter from a programming perspective.

They are technically threads: they are independently scheduled, concurrent units of execution sharing an address space. They're just not OS (or kernel) threads. Hell, technically userspace threads (generally cooperatively scheduled) are the original, they predate kernel threads by a decade or two.

As someone below said, they might be from programming perspective, but technically they are not. See GOMAXPROCS for more info.

That being said the whole `tractable primitive` thing used in the article sounds somewhat sloppy to me. I don't quite get it. Yeah, they could be easier for an agent to write than async/await, but threads are also trivial in that matter, and you'd still need a mutex with go routines.