Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Right, but the point isn't to make errors impossible; the point is to have them be 1) less likely to write, and 2) easier to spot on review.

People's biggest complaints about golang's errors:

1. You have to _TYPE_OUT_ what to do on EVERY.SINGLE.ERROR. SOO BOORING!

2. They clutter up the code and make it look ugly.

Rust is so much cleaner and more convenient (they say)! Just add ?, or .unwrap()!

Well, with ".unwrap()", you can type it fast enough that you're on to the next problem before it occurs to your brain to think about what to do if there is an error. Whereas, in golang, by the time you type in, "if err != nil {", you've broken the flow enough that now you're much more likely to be thinking, "Hmm, could this ever fail? What should we do if it does?" That break in flow is annoying, but necessary.

And ".unwrap()" looks so unassuming, it's easy to overlook on review; that "panic()" looks a lot more dangerous, and again, would be more likely to trigger a reviewer into thinking, "Wait, is it OK if this thing panics? Is this really so unlikely to happen?"

Renaming it `.unwrap_or_panic()` would probably help with both.



Eh, I'm not convinced.

1. Culturally, using `unwrap` is an omerta to Rust developers in the same way `panic` is an omerta to Go devs;

2. In the Rust projects I've seen there is usually a linter rule forbidding `unwrap` so you can't use it in production


> omerta

Unfortunately none of the meanings Wikipedia knows [1] seems to fit this usage. Did you perhaps mean "taboo"?

I disagree that "unwrap()" seems as scary as "panic()", but I will certainly agree to sibling commenters have a point when they say that "bar, _ := foo()" is a lot less scary than "unwrap()".

[1] https://en.wikipedia.org/wiki/Omerta_(disambiguation)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: