3 ms·
Oh Go with Rust's result/none setup and maybe better consts like in the article would be great. Too ba null/nil is to stay since no Go 2. Or maybe they would?
by anttiharju 9mo ago
Oh Go with Rust's result/none setup and maybe better consts like in the article would be great.
Too ba null/nil is to stay since no Go 2.
Or maybe they would? Iirc 1.21 had technically a breaking change related to for loops. If it was just possible to have migration tooling. I guess too large of a change.
- benrazdev 9mo agoTechnically, with generics, you could get a Result that is almost as good as Rust, but it is unidiomatic and awkward to write: type Result[T, E any] struct { Val T Err E IsErr bool } type Payload string type ProgError struct { Prog string Code int Reason string } func DoStuff(x int) Result[Payload, ProgError] { if x > 8 { return Result[Payload, ProgError]{Err: ProgError{Prog: "ls", code: 1, "no directory"}} } return Result[Payload, ProgError]{Val: "hello"} }
- yencabulator 9mo agoNullability is unavoidable in Go because of zero values. https://go.dev/ref/spec#The_zero_value https://go.dev/ref/spec#The_zero_value