News for hackers. Stuff that matters.
Re:Things Go needs more than generics by lima on Monday October 04, 2021 @04:38AM (#28744457)
> It’s crazy how Rust just gets rid of this whole class of bugs with option and result types (and sum types in general).

As a Rust security consultant, many bugs we find in Rust applications are crashes due to .unwrap()... it's easier to spot, but still essentially the same class of bug.

Re:Things Go needs more than generics by rowanG077 on Monday October 04, 2021 @04:48AM (#28744518)
I disagree. A nil error in Go is most likely a dev forgetting a check. An unwrap() is a dev explicitly saying this should always contain a value. In fact fixing unwrap is as easy as search for unwrap in your codebase and factoring them all out.
Re:Things Go needs more than generics by vaylian on Monday October 04, 2021 @08:30AM (#28745808)
> An unwrap() is a dev explicitly saying this should always contain a value

Isn't expect() supposed to cover that case?

Re:Things Go needs more than generics by rowanG077 on Monday October 04, 2021 @09:09AM (#28746206)
No it's the opposite. Unwrap() means the dev said this will never not be set. Expect() is saying if this value is not available exit the program with this user facing error message.
Re:Things Go needs more than generics by ModernMech on Monday October 04, 2021 @09:12AM (#28746235)
expect() is like unwrap() but you can give a message as an argument.
Re:Things Go needs more than generics by mathw on Monday October 04, 2021 @06:19AM (#28744991)
It is a shame there are so many Rust examples out there with unwrap() all over them, because it's really not something I would want to see in production code. expect() with a message if you know that the only reason this fails is because something else messed up that should have prevented the call in the first place, sure. unwrap()? No thanks. That's why we have the ? operator now.
Re:Things Go needs more than generics by da39a3ee on Monday October 04, 2021 @08:57AM (#28746070)
Agreed, except I don't think people should use expect() since its name is a mistake made early on in Rust: people use it to write

expect("something bad we don't expect")

unwrap_or_else(|| panic!(...))

is clear and doesn't suffer from the naming mistake.