Remix.run Logo
Lvl999Noob 2 days ago

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.

2 days ago | parent | next [-]
[deleted]
ptman 2 days ago | parent | prev [-]

So what happens when you write through the nil pointer?

Lvl999Noob a day ago | parent | next [-]

Well, what happens when you write through an invalid pointer? The runtime can swallow the write or crash the program or allocate new storage and replace the pointer. Depends on the wanted semantics.

chuckadams 2 days ago | parent | prev [-]

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