4 ms·
The comparison here is with go. Unwrap would look like: file := os.Open("foo").Unwrap() I'll take that over the current go state of the art: file, e
by TheDong 5y ago
The comparison here is with go.
Unwrap would look like:
file := os.Open("foo").Unwrap()
I'll take that over the current go state of the art:
file, err := os.Open("foo")
if err != nil {
panic(err)
}
Just like "panic(err)" is used infrequently, "unwrap" would be used infrequently. They're comparable, and for the cases where unwrap is okay (test code, once-off scripts, etc), I'd definitely prefer it to the panic boilerplate.
- tptacek 5y agoI don't understand this example at all. A Rust programmer would essentially never use unwrap on the return from File::open. It would be like checking open(2) with assert() in C.
- preseinger 5y agoThat Go would never pass code review unless it is part of a tiny CLI tool or script.