Go Nil Pointers and Rust
getstream.io
getstream.io
I don't see how there is nothing guaranteeing that your references are nonnull. My understanding was that the standard prevents you from having a null reference because the methods of trying to generate one are codified as illegal or performing undefined behavior. Am I wrong here, or misunderstanding what you're trying to say?
ADTs are the way to go. If Go had ADTs I would pick it over Rust in a heartbeat, as I personally don’t care much about not having a GC, and think go-routines are superior to async/await.
But it works well enough that you can write code pretty easily that simply cannot produce npes. Excluding that as source of bugs is nice and should be built into any new language.
Granted, the main downside of OCaml is it still being single threaded. That can be worked around, but it depends on your workload.
The right thing to do is to know statically in your code whether a variable can be nil, or can't. Don't put stupid little nil checks in every function, but maybe do so when storing a field, e.g. to ensure an object holds valid state.
If your biggest problem is surprise nil pointer values, then that's good for you, because they're relatively easy bugs to track down.
If Rust hypothetically wanted to add named return values, I think the way they'd do it is have the compiler check that all codepaths through the function initialize the returns. In general rustc is happy to let you declare uninitialized variables, and even partially initialize them field-by-field, as long as it can prove to itself that everything's fully initialized by the time you read it.
func main() { var a A a.getB().getM() }
type A struct { B B; }
func (a A) getB() B { log.Println("getB") if a != nil { return a.B; } return nil }
type B struct { M string; }
func (b *B) getM() string { log.Println("getM") if b != nil { return b.M; } return "" }
Everything is nil but they both got executed! Obviously, you should use this selectively, but it's there!
Algebraic Data Types always seemed more elegant when I've seen them in other languages, anyone have anything but positive things to say about them?