3 ms·
I propose eliminating Null/None all together. Simply do not allow a pointer to be initialized to none, but require it to point to an object. The object should
by ovi256 17y ago
I propose eliminating Null/None all together. Simply do not allow a pointer to be initialized to none, but require it to point to an object. The object should not be collected as long as the pointer is valid.
Just throw exceptions if you need to, and handle those. Semantically, exceptions and special null values are the same - they let you know something went wrong. However, I think that null values are a syntactic oddity much like a vestigial limb now that we have exceptions.
- limmeau 17y agoWhat do you suggest as a replacement for nullable fields?
- ovi256 17y agoOuch, forgot that. Well, I guess the database could use Null values internally, but they should be translated into exceptions as soon as possible - as in, throw a NullFieldException if the field is accessed. However, checking for these all the time would be just as wasteful as checking for null values. I now see the advantages of the monad way.
- stcredzero 17y agoIn a statically typed OO language, why not have an implicitly created MissingObject? Whenever you define a class Foo, you automatically get MissingFoo for which you must define any methods that Foo understands.