4 ms·
The simple existence of "Not an object" value is fine. The abstraction built over the raw value should be good enough that it will confront you when you attempt
by t0suj4 5y ago
The simple existence of "Not an object" value is fine. The abstraction built over the raw value should be good enough that it will confront you when you attempt to use it.
The next level is constructing types in a way that you can avoid such low level details of whether the pointer is valid.
In other words, encode the state in the type instead of a value that you need to test against every time you want to use it.
- anamax 5y agoThat's easier said than done, and it's not obvious how to do it with types. Consider a non-blocking read. What the caller does depends on whether the read returns a value or "no data available". If the type of the object returned depends on whether there was a value, you just replaced a null check with a type check. You can avoid that check with a caller with multiple return points and have the callee pick between them. Exceptions are the most obvious way to do that. However, exceptions happen immediately, while type/null checks can be done later.