3 ms·
That's not exactly what Go does, as you can return much more information and it's almost always clear what's an error and what isn't (there are a few exceptions
by arp242 6y ago
That's not exactly what Go does, as you can return much more information and it's almost always clear what's an error and what isn't (there are a few exceptions, such as strings.Index() returning -1).
- loopz 6y agostrings.Index() => -1 is not an error, but a result, ie. empty result is not an error. A more sophisticated type system would provide more differentiation, but that also have costs. Golang's errorhandling, I wouldn't say it's great, but it let's you be explicit about the errorhandling itself, which may lead to performant quality code. I believe it follows C errorhandling by design, but answers the age old "wish I could return an error in addition to return value here". Golang grants that wish, and even provides some compile errors if error value is not assigned to. Handling the error is left as an exercise though, so code shouldn't be too complex. Index() returning -1 is natural for typical usage, when following conventions such as used in C-type languages. It seems to be a feature, appreciated by many, though with costs and benefits attached.
- throw_m239339 6y ago> That's not exactly what Go does, as you can return much more information and it's almost always clear what's an error and what isn't (there are a few exceptions, such as strings.Index() returning -1). Yes it is exactly what Go does. Look, I'm "returning" an "out" parameter from my C function here. I can also return an "out" error in form of a "struct * error_return" if I wanted to, with a char * member or whatever. This is not error handling baked in C either, just like Go. There is nothing "awesome" with doing that. I could do that in any language and nobody would call that "awesome".
- Normille 6y agoAmericans [and wannabe Americans] are very easily "awed" -judging by the sheer number of things they find "Arse-Sum". https://stiobhart.net/2015-03-23-arse-sum/ https://stiobhart.net/2015-03-23-arse-sum/