←back to thread

Go channels are bad

(www.jtolds.com)
298 points jtolds | 8 comments | | HN request time: 0.729s | source | bottom
Show context
Jabbles ◴[] No.11210740[source]
Effective Go has always said:

Do not communicate by sharing memory; instead, share memory by communicating.

This approach can be taken too far. Reference counts may be best done by putting a mutex around an integer variable, for instance.

https://golang.org/doc/effective_go.html#sharing

replies(3): >>11210862 #>>11210978 #>>11210990 #
1. api ◴[] No.11210978[source]
I thought Go had gc. Why would you ever need reference counts?
replies(2): >>11211015 #>>11211294 #
2. voidlogic ◴[] No.11211015[source]
Non-memory resources that exist within your application.

Example: Perhaps once no instances of an object are in use, you want to remove that object from persistent storage such as a DB.

replies(1): >>11211115 #
3. api ◴[] No.11211115[source]
Does Go not have finalizers? These are mostly solved problems since the Smalltalk era. Haven't learned Go yet and from what I read I'd be better off with Rust or something that would stretch my brain more like Haskell. When I read about it I get the sense that we are reinventing stuff from the 90s. But hey, it's hip.
replies(3): >>11211141 #>>11211151 #>>11211331 #
4. catnaroek ◴[] No.11211141{3}[source]
Sometimes you need to guarantee that resources are cleaned up in a timely fashion. Finalizers don't help here.
5. hacknat ◴[] No.11211151{3}[source]
Piggy backing off @catnaroek, go does have finalizers too though.
6. chrsm ◴[] No.11211294[source]
Example: Recently built a small service that responds to requests and walks various files looking for data.

The service can be asked to unload (close) the file, but it's hard to say whether it's in-use at the time without some kind of reference count to current requests using the file.

replies(1): >>11211343 #
7. pcwalton ◴[] No.11211331{3}[source]
Go does have runtime.SetFinalizer: https://golang.org/pkg/runtime/#SetFinalizer

But beware of finalizer ordering issues.

8. nly ◴[] No.11211343[source]
That's kinda what dup() is for. Reference counting happens in the kernel.