top | item 33588329

(no title)

coddle-hark | 3 years ago

Here’s one: The fact that contexts are used extensively in the standard library but that there’s still no way to cancel a write to an io.Writer. The only way to “cancel” a write on a TCP socket is to set the socket’s “deadline” to some time in the past from another goroutine.

discuss

order

ainar-g|3 years ago

I agree that this is a PITA, but this really is more of a growth pain than an initial design flaw. Contexts have appeared way after the Go 1.0, when the entire ecosystem has already gotten used to io.Reader and io.Writer.

If you want a much more annoying example of inconsistency in the initial language design, look at the behaviour of nil and closed channels:

- sending data to a nil channel blocks forever;

- receiving data from a nil channel blocks forever;

- sending data to a closed channel causes a panic;

- receiving data from a closed channel is fine: you receive the zero value, forever.

I can understand the logic behind the last two (sending to a closed channel is an error in program logic, and closing a channel is a common idiom for broadcasting completion of a task to several goroutines), but the first two are just a massive footgun, and, in my opinion, should cause panics instead.

silisili|3 years ago

Agreed on that one. Contexts definitely feel bolted on and unnatural. The sql libs for example all have 'Do' and 'DoContext', where 'Do' is any one of the operations you'd typically use.