3 ms·
So wait, go has handle errors by returning them, but it also doesn't force you to actually handle all return values? I thought that was the entire point of impl
by xxpor 5y ago
So wait, go has handle errors by returning them, but it also doesn't force you to actually handle all return values? I thought that was the entire point of implementing error handling like that.
How are we still repeating the same mistakes C made 50 years ago?
- ipsi 5y agoYou're sort of forced to handle them, in that if a function returns (Data, error), you need to assign the error to a variable (or do data, _ := func(), but at least that indicates you're intentionally ignoring the error), and since Go treats unused variables as a compile failure, you might as well check them properly. But there's nothing that says you must check them, no.
- xxpor 5y agoAh thanks, that's kind of what I thought. I've read examples of Go but haven't written a line of it myself. the way GP described it made it sound like foo, err = bar() was merely a convention and you could do foo = bar() and drop err. If you have to add ", _" that's fine.