4 ms·
Here's a good article form rob pike on one way to look at how Go can handle errors https://go.dev/blog/errors-are-values https://go.dev/blog/errors-are-values
by recov 4y ago
Here's a good article form rob pike on one way to look at how Go can handle errors https://go.dev/blog/errors-are-values https://go.dev/blog/errors-are-values
- nprateem 4y agoExtra complexity to work around a shortcoming which ignores the fact that most users of a library only care about errors at the top level. Passing errors around manually when the machine could do it is a waste of time however it's dressed up.
- nemothekid 4y ago>Passing errors around manually when the machine could do it is a waste of time however it's dressed up. You, the writer, pass around errors manually so that the reader, who interfaces with the code 10x more than the writer, is able to reason about the code. Go's errors handling sucks, but I don't think everyone has the same opinion on why it sucks; I personally think that sum types should be added to the language making it impossible for errors to be silently ignored. Exceptions, while convenient, require too much discipline to use cleanly.
- nprateem 4y agoSomehow after 25 years of coding I've never seen issues with using exceptions. Java is more explicit, Python gets the job done, and a good IDE helps in most cases anyway
- jatone 4y agoevery java team i've worked with handles their exceptions by making them runtime exceptions to bypassing the very thing you're pro-porting.
- erik_seaberg 4y agoUnchecked exceptions work fine. Basic stuff like stream.map(f) is unusable when f throws any checked exception, so the Java world largely stopped declaring them. I consider it a miss in Java’s generics when lambdas and method refs were added.
- jatone 4y agoI didn't say unchecked exception don't work. I was pushing against the assertion that 'Java is more explicit'; its not since java developers actively work to avoid using the damn feature being mentioned.
- nemothekid 4y ago>Somehow after 25 years of coding I've never seen issues with using exceptions Here is a link to Google's C++ style guide, which discourages exceptions with pros & cons: https://google.github.io/styleguide/cppguide.html#Exceptions https://google.github.io/styleguide/cppguide.html#Exceptions It's your 25 years of coding, vs the several thousand man-months of Google's C++ codebase. That said, I don't deny that some people use exceptions with little mental overhead. I've been told about very high performance and readable trading software that made use of exceptions. My main gripe is that it they require discipline to use correctly, almost everyone uses them differently, and they make code harder to reason about. I would prefer a language that doesn't need an IDE to locally reason about some piece of code.
- nprateem 4y ago"Things would probably be different if we were starting over from scratch" They concluded against them due to problems integrating into legacy code which is fair enough
- pjmlp 4y agoGoogle's style guide is well known in the C++ community for not being that much worth to look into it.
- kaba0 4y agoAs others mentioned, Google’s C++’s guide is simply not that relevant. And don’t forget the principle use case of C++ - it is a low level language. While exceptions are pretty cheap overall, they can be expensive in some niche cases which do happen more often in C++ than in python. I really haven’t heard a good case against exceptions per se — they make it possible to handle every error at an appropriate place. And bubbling the error up to possibly a much higher place is exactly the needed approach many times (e.g. returning a http error code on an unrecoverable mistake)