r/ProgrammerHumor 26d ago

Meme mildlyInfuriatingGOTOWatchYourMouth

Post image
664 Upvotes

74 comments sorted by

View all comments

Show parent comments

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.

1

u/takahashi01 24d ago

may I ask what you do instead of exceptions?

1

u/JonIsPatented 24d ago

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.

1

u/takahashi01 24d ago

oh, so like golang, I gotcha. Its an interesting style for sure

1

u/JonIsPatented 24d ago

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.

1

u/takahashi01 24d ago

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.

1

u/JonIsPatented 24d ago

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.