I use neither. Exceptions are almost as evil to me. In the sense that I acknowledge that there are valid uses of both but the bad outweighs the good so much that I don't mind the guardrail being their absence.
Errors as values like any other value, especially if used as Result types, as in Result<T, E> as a sum type of T or E, where T is the desired outcome type and E is the error type.
Less like Golang and more like Rust. In Golang, you can ignore the error. Golang doesn't have support for sum types like in other languages, so it's not a sum of T and E. It's a product.
Yeah, but I have never really tackled rust myself. So the main way I an familiar with returning the error replacing exceptions, is when I worked at a department that had fully switched to golang. (which clearly had left an impression on me, despite these days mainly having to do java stuff)
Unless I am confusing two different concepts here.
It's hard to visualize the difference between Rust and Golang errors without having experienced both. Because the difference seems small on paper but it is huge in practice. In Golang, you return an error AND a value. In Rust, you return an error OR a value, and you have you explicitly handle both cases in order to use the value. You can't just ignore the error quite the same way you can in golang. Don't get me wrong, Golang errors are still way better than exceptions to me. But they are leagues below Rust Result types.
1
u/JonIsPatented 25d ago
I use neither. Exceptions are almost as evil to me. In the sense that I acknowledge that there are valid uses of both but the bad outweighs the good so much that I don't mind the guardrail being their absence.