Option<T> and Result<T>: No More Nil Pointers
Go to Rust Series: ← String vs &str | Series Overview The Problem: Nil and Errors Tony Hoare (inventor of null references) called it his “billion-dollar mistake.” Go’s approach: nil values and explicit error returns Rust’s approach: Option<T> for absence, Result<T, E> for errors Go: Nil Pointers Go: func findUser(id int) *User { if id == 0 { return nil } return &User{ID: id, Name: "Alice"} } func main() { user := findUser(0) if user != nil { fmt.Println(user.Name) } else { fmt.Println("User not found") } } Problem: Easy to forget nil check: ...