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.
- ++

Reply via email to