4 ms·
I’ve been bitten by it in production. Whenever I see this partial result pattern, it’s always a function that USUALLY returns nil plus an error. In one special
by et1337 3y ago
I’ve been bitten by it in production. Whenever I see this partial result pattern, it’s always a function that USUALLY returns nil plus an error. In one special case, it returns a partial result plus an error. This is a nil pointer panic waiting to happen.
- beautron 3y agoThe caller can check if the result != nil. If I get a result that came with a non-nil error, and I still plan to do something with the result, then it seems natural to think about the possibility that the result might be nil. I would consult the function's documentation, and maybe its source, and then maybe put in a nil check. This is too rare a problem to be worth adding complexity to the language. There needs to be a big payoff for adding complexity. A language gets hard to use if it adds micro-complexities all over the place for the sake of preventing rare programming mistakes.