5 ms·
My whole point is that following the convention basically guarantees shadowing in many contexts. That's bad.
by zachmu 2y ago
My whole point is that following the convention basically guarantees shadowing in many contexts. That's bad.
- sethammons 2y agoDo you also do err, err2, someOtherErr? Shadowing is the exact same situation. Errors are just values
- zachmu 2y agoYes, it is the same situation. No, we don't tend to use unique names for errors. The idiom is just too strong. This is somewhat mitigated by consistent consecutive error handling, meaning you always immediately dispatch an error on the line after assigning it. Every time we have had bugs because of this, it's because someone tried to be clever and delay handling an error until slightly later (like at the end of an if else chain where each branch might have had an error).
- kiitos 2y agoSure, and every `x, err := f()` shadows any previous `err`. This kind of shadowing is totally normal and idiomatic, in no way bad.
- zachmu 2y agoerr has the same problem as ok, it's true. It's a messy, kind of embarrassing spot in the language and idioms, not something to celebrate.
- kiitos 2y agoI'm not sure how useful it is to adjudicate what is ultimately just a property of the language. It's not something to celebrate, or mourn, or (importantly) try to work around, it's just the way things work. It seems like you're just fighting the language. This is not the path to success :)