4 ms·
> Here's one of them, which follows a common recommendation in the Go community to use a sentinel error to represent the "value not found" condition. Is this r
by manlobster 2y ago
> Here's one of them, which follows a common recommendation in the Go community to use a sentinel error to represent the "value not found" condition.
Is this really a common recommendation in the Go community? Seems like returning `bool` to indicate if the value was found is somewhat of a no-brainer, since it follows the familiar approach used for map lookups and type assertions.
- segfaltnh 2y agoI've certainly seen and emulated this pattern in a lot of Go code. I don't know if I am representative of the larger community. I often use bool unless there are other error conditions (and there often are), but this article is definitely making me wonder if this is ideal.
- abound 2y agoThere are at least two places in the standard library that behave like this: sql.ErrNoRows and the error thrown by os.Open when a file doesn't exist.
- manlobster 2y agoTrue, but both of these are for relatively slow operations, where the performance of the error checking is relatively insignificant.
- zachmu 2y agoIt has also become somewhat common to use io.EOF to signal the end of iteration, like the reader libraries do.