Hacker News new | ask | show | jobs
by jahewson 469 days ago
It's not the null that's the issue, it's the type system. As long as you have algebraic data types you can have safe null.

Ocaml's `None | Some of int` has the same basic meaning as TypeScript's `number | undefined`

1 comments

That’s not the same thing as a nil pointer though.

Go data types cannot be null but a pointer to a data type can be. And what a nil pointers is, is a valid type of pointer but which points to an invalid point or memory.

Typescript doesn’t have the same problem because it doesn’t have pointers.

Rust somewhat this problem with its borrow checker but it’s still entirely possible to create a nil pointers in Rust and without using ‘unsafe’, but admittedly it’s not by writing idiomatic Rust.

Go really should do more to prevent issues here but the real problem is around the creation of “objects” (since Go isn’t fully OOP) and how you can’t really create an image struct (nor even map) and have it default as empty. I’m sure the logic behind that is for performance, but why not expose the option of an uninitialised struct pointer behind ‘unsafe’ for those who are willing to accept that risk?