4 ms·
How about a simple one liner like (just throwing out random ideas; I'm sure these are not idiomatic) return when err return if err return ?> err
by CharlieDigital 2y ago
How about a simple one liner like (just throwing out random ideas; I'm sure these are not idiomatic)
return when err
return if err
return ?> err
return ? err
Still readable, still pretty explicit IMO.
- vbezhenar 2y ago`return err` is a terrible approach. You must wrap the error with new error, include file and line information, so stacktrace is actually useful. When program spews some random garbage into its stderr and you have no idea where that message came from (imagine looking through millions of lines of kubernetes implementation), that's the good way to ensure that nobody would even care to look at it. Thousands of unsolved issues in kubernetes tracker is a perfect demonstration of it. Go is just bad at handling errors. Exceptions are superior in every way.
- CharlieDigital 2y agoEven that could be fixed right? return when err return if err return ?> err return ? err to: return when stackify(err) return if stackify(err) return ?> stackify(err) return ? stackify(err) I don't know; I'm just throwing ideas out there. I do agree that exceptions are just fine and it's not like you couldn't just catch and return exceptions if you wanted to like err.
- vbezhenar 2y agoThey definitely could introduce a shorter syntax like Rust did. And they discussed that, but apparently they were not happy with ideas so far, so it's postponed. May be some day.