4 ms·
The thing that's always annoyed me about the way go does this, where extra return values are treated somewhat specially to encourage you to actually check them,
by stormbrew 12y ago
The thing that's always annoyed me about the way go does this, where extra return values are treated somewhat specially to encourage you to actually check them, if your function returns only a success/failure condition you're either forced to return a dummy value for no reason and ignore it, or allow the condition to go unchecked.
Meanwhile, the actual concept of option type has been around for ages and could have been used instead of trying to twist MRV into it.
Thankfully, all the other newer languages are doing the right thing imo.
- NateDad 12y agoNot sure what you mean by needing a dummy value if your function only returns success/failure. That's what a boring old error return is for. func foo() error
- stormbrew 12y agoYes, but unlike having a second result this particular error check need not be touched. To make it so the caller has to check it, I'd have to return a dummy normal return.
- NateDad 12y agoYou can always call a function and not assign the return calls to anything. If you have func foo() (string, error) You can still call it thusly: foo() However there are tools to check for unchecked errors like this one: https://github.com/kisielk/errcheck https://github.com/kisielk/errcheck