News for hackers. Stuff that matters.
Re:Go Replaces Interface{} with 'Any' by johnisgood on Tuesday December 14, 2021 @08:37PM (#29560933)
Huge no to anything that will require .unwrap() noise everywhere in the codebase. I use Erlang, my code does not have ".unwrap().unwrap()"[1] anywhere.

[1] https://github.com/SeaQL/sea-orm/blob/64c54f8ad603df0c1d9da8...

Re:Go Replaces Interface{} with 'Any' by eru on Tuesday December 14, 2021 @11:50PM (#29562237)
That's actually a problem in Erlang.

In Haskell, 'Maybe (Maybe Int)' is a different type from 'Maybe Int'.

That means that when you use eg a hash table that returns some kind null value like 'Nothing' on lookup when a key is not found, you can still stick exactly that kind of null value as a normal value into the table and everything will turn out fine.

Re:Go Replaces Interface{} with 'Any' by TheDong on Tuesday December 14, 2021 @10:22PM (#29561693)
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.
Re:Go Replaces Interface{} with 'Any' by tptacek on Tuesday December 14, 2021 @11:08PM (#29561977)
I 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.
Re:Go Replaces Interface{} with 'Any' by preseinger on Wednesday December 15, 2021 @02:43AM (#29563120)
That Go would never pass code review unless it is part of a tiny CLI tool or script.
Re:Go Replaces Interface{} with 'Any' by imron on Tuesday December 14, 2021 @09:37PM (#29561396)
I use rust and my code does not have .unwrap() (and definitely not .unwrap().unwrap()) in it either. That's what the ? operator is for.
Re:Go Replaces Interface{} with 'Any' by eru on Tuesday December 14, 2021 @11:51PM (#29562247)
The '?' is not a conceptual advance over .unwrap(), it's "just" a major syntactic convenience.
Re:Go Replaces Interface{} with 'Any' by ComputerGuru on Wednesday December 15, 2021 @02:10AM (#29562947)
Of course it is. Unwrap panics on error, while ? bubbles up the error instead. But ? wasn’t introduced to replace unwrap, unwrap was always frowned upon. It instead replaces match and return.
Re:Go Replaces Interface{} with 'Any' by imron on Wednesday December 15, 2021 @04:17AM (#29563662)
It was always frowned upon, but still ended up everywhere (including lots of documentation and example code) because it was less verbose than the match handling. The ? helped remove that last obstacle.