Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 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.



I'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.


There 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.


True, but both of these are for relatively slow operations, where the performance of the error checking is relatively insignificant.


It has also become somewhat common to use io.EOF to signal the end of iteration, like the reader libraries do.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: