Reading the examples I found myself thinking, “that looks like a really useful pattern, I should bookmark this so I can adopt it whenever I write code like that.”
The fact that I’m considering bookmarking a blog post about complex boilerplate that I would want to use 100% of the times when it’s applicable is a huge red flag and is exactly why people complain about Go.
It feels like you’re constantly fighting the language: having to add error handling boilerplate everywhere and having to pass contexts everywhere (more boilerplate). This is the intersection of those two annoyances so it feels especially annoying (particularly given the nuances/footguns the author describes).
They say the point is that Go forces you to handle errors but 99% of the time that means just returning the error after possibly wrapping it. After a decade of writing Go I still don’t have a good rule of thumb for when I should wrap an error with more info or return it as-is.
I hope someday they make another attempt at a Go 2.0.
Just pass along two hidden variables for both in parameters and returns, and would anything really change that the compiler wouldn't be able to follow?
i.e. most functions return errors, so there should always be an implicit error return possible even if I don't use it. Let the compiler figure out if it needs to generate code for it.
And same story for contexts: why shouldn't a Go program be a giant context tree? If a branch genuinely doesn't ever use it, the compiler should be able to just knock the code out.
ashishb•2h ago
Is there any equivalent in major popular languages like Python, Java, or JS of this?
gzread•2h ago
There's a stop_token in some Microsoft C++ library but it's not nearly as convenient to interrupt a blocking operation with it.
ndriscoll•2h ago
nnx•2h ago
https://github.com/ggoodman/context provides nice helpers that brings the DX a bit closer to Go.
drdaeman•2h ago
perfmode•2h ago
deathanatos•1h ago
(I also think there's some wonkiness with and barriers to understanding Python's implementation that I don't think plagues Go to quite the same extent.)
lifis•1h ago
richbell•1h ago
tadfisher•23m ago
Quekid5•1h ago
Also, a sibling poster mentioned ZIO/Scala which does the Structured Concurrency thing out of the box.