Non-null objects, the Null Object pattern, and T.init
Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang at gmail.com>
Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang at gmail.com>
Sun Jan 19 04:29:13 PST 2014
On Sunday, 19 January 2014 at 10:32:36 UTC, Jacob Carlborg wrote:
> I think nil (null) works quite nicely in Ruby. nil is a
> singleton instance of the NilClass class. Since it's an object
> you can call methods on it, like to_s, which returns an empty
> string. It works quite well when doing web development with
I have no experience with Ruby, but Javascript also do this
(undefined is an object). I don't think it is more work to debug
Python and Javascript null exceptions than C-like code.
I think it was a mistake to let zero represent null, and it was
probably done to make testing faster. But a different bit-pattern
could prevent conflation between memory corruption and null. It
is highly improbable that an address like $F1234324 is the result
of memory corruption.
Another advantage with null-objects as a pattern and mechanisms
to support it is that you can have multiple variants and
differentiate between:
- undefined (not initialized)
- null (deliberately not having an attribute)
- application specific null values (like, try-again,
lazy-evaluation) etc that depending on context evaluates to
undefined, null or tries to fetch the values by computation.
- ++
More information about the Digitalmars-d
mailing list