4 ms·
> they're just addresses, where nil is a very useful value It is actually the other way around, having a way to represent “no pointer” is fine. What’s missing
by DougBTX 4y ago
> they're just addresses, where nil is a very useful value
It is actually the other way around, having a way to represent “no pointer” is fine. What’s missing is the ability to check at compile time that a pointer is not nil.
- jonathanstrange 4y agoDynamic memory allocation is a runtime operation and can always fail, so this cannot in general be a compile-time operation if you also want to allow dynamic memory allocation.
- DougBTX 4y agoThere are two common ways to deal with failable operations: either throw/panic/abort instead of returning a value if creating the value fails, or return a container which must be checked for success before the value can be accessed. The key is that once a value has definitely been obtained, the compiler needs to be able to track that, otherwise it is unclear whether the value needs to be checked again whenever it is used. Often those checks are not where they should be, leading to many bugs.