4 ms·
That'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 ret
by anamax 5y ago
That'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.