Remix.run Logo
treis 5 hours ago

It sets primitives to 0, "", false etc. Which is almost always but not always fine. And if they're complex objects you still get NPEs

To get true nullable fields you need to use pointers. That's a whole topic in itself but they're awkward.

It's much worse than true nullable objects that your compiler can check for NPEs. It throws fewer NPEs but at the expense of data integrity where you don't know if your 0 is actually a 0 from the user or a null.

Lvl999Noob 3 hours ago | parent [-]

What if Go went all the way? Referencing a zero pointer (nil) gives you the zero value of the pointed to type. If you try to access a zero map, it tries to deference the zero pointer to the underlying buffer. The zero pointer gives you the zero slice with zero length. The presence check fails without crashing and you get some pretension of reasonable behaviour.

ptman 2 hours ago | parent | next [-]

So what happens when you write through the nil pointer?

chuckadams 42 minutes ago | parent [-]

Nil of course (nothing happens). Not saying it’s a good idea, it would just be consistent.

2 hours ago | parent | prev [-]
[deleted]