News for hackers. Stuff that matters.
Re:Thirteen Years of Go by ilyt on Friday November 11, 2022 @03:04PM (#33566068)
>Error handling is strictly worse than pretty much any other language out there — you are only making you believe that you are handling your error cases. A pragmatic “handle it here or bubble it up” is a much better approach, as more often than not you can’t actually handle the error at call site.

It could've definitely be better (just Rust-like Result<T> type would make it so much clearer to handle) but Go's insistence of dealing with it here and now means you have to think about what is exactly happening when it errors out, and are encouraged to add context to the error message instead of "here is stack trace, fuck you user, you're not worth knowing what is wrong".

But it's verboseness in common cases is inexcusable, if I have 3 steps to establish a connection, having 3 lines per error to handle is inexcusably bad. And it will be fucking 3 lines even if you write it in one line, because go fmt will expand it back to 3 lines

> Goroutines in themselves won’t give you actually correct concurrency.

Main advantage is they are cheap enough that doing goroutine per request won't bite you in most cases so you can have near-perfect parallelization of common apps by just writing essentially serial code.

The concurrency primitives are built into language and stdlibs which means when you do need synchronization, everyone does it same way.

Re:Thirteen Years of Go by Gwypaas on Friday November 11, 2022 @03:15PM (#33566207)
> The concurrency primitives are built into language and stdlibs which means when you do need synchronization, everyone does it same way.

As long as you after refactor N still are staying in the happy path avoiding the numerous footguns and implicit behavior Go supplies you with.

I would say if you stray outside a single thread or shared nothing fire up a Goroutine per response architecture deeply reconsider the choice of using Go.

https://www.uber.com/en-US/blog/data-race-patterns-in-go/

Re:Thirteen Years of Go by Xeoncross on Friday November 11, 2022 @04:45PM (#33567289)
> are encouraged to add context to the error message instead of "here is stack trace, fuck you user, you're not worth knowing what is wrong"

haha, so true. I almost always wrap errors at every level with addition context. If it was worth doing, then it's worth explaining.

People that prefer try/catching large sections of functionality or want to skip verbose handling of errors often have not thought through the user or tester experience. Heck, even trying to recreate the issue/state from production.

if err != nil { return err }

vs

if err != nil { return fmt.Errorf("context here: %s: %w", action_type, err) } (or wrapping some custom app error with context for the trace)

Of course you don't want to leak private details, but often there is a public component that is worth adding. This also brings up the concept of dual-error chains where what you log and what you report to the client are different.

Re:Thirteen Years of Go by kaba0 on Friday November 11, 2022 @05:02PM (#33567485)
You surely know that it is very common to rethrow the original exception wrapped in languages with try-catch — it still saves you the time to write that (plus it is safe, no code, plus stacktrace). It is still strictly better than whatever go has.
Re:Thirteen Years of Go by Xeoncross on Friday November 11, 2022 @06:02PM (#33568001)
I've written a lot of try/catch but no one in those languages do that for every branch, it's usually just everything wrapped in a big try/catch.

Go makes you deal with the error every single time something could go wrong, so you have a chance to do the right thing and append context at every single failure path.

Re:Thirteen Years of Go by kaba0 on Friday November 11, 2022 @09:01PM (#33569252)
Go makes you believe you dealt with the error, but instead you just forget about it.

Also, checked exceptions are very much not like that, and being able to handle errors of a logical unit is also beneficiary (e.g. transactions). You are free to use the scope-size that makes sense for the given use case.

Re:Thirteen Years of Go by Xeoncross on Saturday November 12, 2022 @04:05PM (#33577069)
> Go makes you believe you dealt with the error, but instead you just forget about it.

Can you explain that? Touching every context of an error propagation seems opposite of forgetting about it.

Re:Thirteen Years of Go by CoolCold on Saturday November 12, 2022 @01:51AM (#33570709)
> Go's insistence of dealing with it here and now means you have to think about what is exactly happening when it errors out

I read it as "let's stop pretending we are wizardy wizards and can do things right way in 100% cases and let the language to enforce us to handle errors, producing better result for average Joe SR SWE".

Am I right with my readings (i'm not a dev guy at all)?

Re:Thirteen Years of Go by Xeoncross on Sunday November 13, 2022 @02:06PM (#33586258)
Yes, every process a person/language/company/country/etc.. adopts has a cost. It's not free. The question is if being forced to always deal with errors is worth the cost of always dealing with errors.

I think it is. I will gladly trade a couple of hours of extra error handling code every week in exchange for no pager duty alarms on the weekend.