Get the latest tech news

Go: Sentinel errors and errors.Is() slow your code down by 3000%


An exhaustive set of benchmarks on different ways to approach error handling in Golang. We demonstrate that common sentinel error idioms are slow your code down by 30x.

But in the (usually more common) case when the value is found, it's much better than starting with a direct error constant comparison, performing just as well as the boolean strategy. Earlier this month I kicked the hornet's nest by suggesting that you shouldn't name boolean map check variables ok. Going back further, lots of luminaries and philosophers in the field have given the same advice in other contexts and for other languages: don't use errors for control flow.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Code

Code

Photo of Sentinel errors

Sentinel errors

Related news:

News photo

Don't DRY Your Code Prematurely

News photo

Mistral Releases Codestral, Its First Generative AI Model For Code

News photo

Mistral releases Codestral, its first generative AI model for code