3 ms·
Perhaps. But if Go itself adds exceptions they're going to have to catch a MassDeveloperExodusException. The standard reason I see for people wanting exceptio
by reificator 8y ago
Perhaps. But if Go itself adds exceptions they're going to have to catch a MassDeveloperExodusException.
The standard reason I see for people wanting exceptions in Go is because they're sick of writing the following:
```go
thing, err := things.New()
if err != nil {
log.Fatalln(err.Error()) // Or `return err`
}
```
But I would argue that it means they're not writing idiomatic go. A good reference for the value of error values is this go blogpost[0]. The HN discussion[1] of that post was also interesting, I like this comment in particular:
> In Go I not infrequently make use of a non-nil value AND a non-nil error. A canonical example of this is the io.Reader interface in Go's standard library [1]. I think it is a very useful idiom particularly when dealing with things where failure is more normal - e.g. dealing with network services, disk IO, decoding partially corrupt exif data from images. Often you want a best-effort at the value even if you run into problems.
Handling every error from every function that returns an error can be verbose. But for that verbosity you get a much easier to understand failure model, and the tools (defer) to handle failures reliably no matter what comes up. Exceptions are part of the reason that RAII is so critical in the C++ world.
[0]: https://blog.golang.org/errors-are-values https://blog.golang.org/errors-are-values
[1]: https://news.ycombinator.com/item?id=8877502 https://news.ycombinator.com/item?id=8877502
- gnode 8y agoOn HN, you can quote code by prepending each line with four spaces, but there is no syntax highlighting.
- reificator 8y agoThanks for the tip, but I avoid that because it ruins readability on mobile IMO.
- HeyImAlex 8y agoEh, rust’s result type has shown that you can do the same thing in way that is more type safe and more ergonomic.
- reificator 8y agoSure, if I had proper sum types + pattern matching in go that'd be great. I'm just saying that I'd prefer the status quo over adding exceptions specifically.
- HeyImAlex 8y agoOh for sure.
- iainmerrick 8y agoExceptions are part of the reason that RAII is so critical in the C++ world. I don’t think that’s quite true. You definitely want RAII with exceptions, yes, but RAII is extremely useful even without exceptions. I believe it’s common to disable C++ exceptions but still use RAII. If you have multiple returns from a function (which can very easily happen with manual error checking) RAII is a big win.
- reificator 8y ago> You definitely want RAII with exceptions, yes, but RAII is extremely useful even without exceptions. Which is another way of saying exceptions are part of the reason for RAII.
- iainmerrick 8y agoYesssss, but, I still think that’s misleading. It’s like saying ATMs are part of the reason for cash.