3 ms·
This is really a Go wart, in my opinion. Go forces you into this pattern, because there's no other way if you want to use defers. So while it's true that it's a
by lobster_johnson 9y ago
This is really a Go wart, in my opinion. Go forces you into this pattern, because there's no other way if you want to use defers. So while it's true that it's a legit use of named return values, it's an unfortunate one, too.
- donatj 9y agoI feel like a lot of deferred errors go unhandled because inexperienced devs don't know that they can.
- weberc2 9y agoI don't do it, but mostly because all I would be doing is logging the error, and if some day it takes me a little longer to root cause some odd file close error, I'll still come out ahead.
- dullgiulio 9y agoThat's one big reason why naked returns are frowned upon. It's much easier to read code where there is a clean "return nil, fmt.Errorf(...)".