Many of these meanings seem to be captured in some modern solutions already:
- We plan to provide a value, but memory for this value hasn’t been allocated yet.
- The memory has been allocated, but we haven’t attempted to compute/retrieve the proper value yet
- We are in the process of computing/retrieving the value
Futures?
- There was a code-level problem computing/retrieving the value
Exception? Result
monads? (Okay, yea, we try to avoid the m word, but bear with me there)
- We successfully got the value, and the value is “the abstract concept of nothingness”
An Option
or Maybe
monad?
- or the value is “please use the default”
- or the value is “please try again”
An enumeration of return types would seem to solve this problem. I can picture doing this in Rust.
One case where I find it useful, tho it operates in a more limited way, is code in block blocks within code comments in Rust, which are also printed out in the generated documentation. They essentially get ran as part of your unit tests. This is great for making sure that, eg, your examples left in code comments actually work, especially if they’re written in a way that functions like a unit test.