3 ms·
It's nil and not null, and the pattern you'll see much more often (in my experience) is if res, err = func(); err != nil {}. Checking for an error to be nil se
by dx034 10y ago
It's nil and not null, and the pattern you'll see much more often (in my experience) is if res, err = func(); err != nil {}.
Checking for an error to be nil seems unusual, as you'd continue with your code in that situation.
And the code isn't that long, don't think it really bloats up the code.
- shadowmint 10y agoWhat ever; irrelevant semantics. The point being made was go has verbose error handling. It does. So does rust; we don't need to dance around it. Better is a different question, but that wasn't the point the OP was making.
- dx034 10y agoI didn't want to nick-pick here, OP could've just said that. It's the same as not having a ternary operator. Go is no language that allows expressing code in few lines, but by that they keep it simple to read. Even though I doubt that proper exception handling is shorter than the Go version. Many developers just choose to not do that and handle all Exceptions the same, or using try-catch blocks that stretch over hundreds of lines. It's indeed faster then, but not a good comparison.