Non-null objects, the Null Object pattern, and T.init

Jacob Carlborg doob at me.com
Sun Jan 19 02:32:35 PST 2014


On 2014-01-19 00:34, "Ola Fosheim Grøstad" 
<ola.fosheim.grostad+dlang at gmail.com>" wrote:

> I have not argued for not having a null. I have argued for trapping
> null, instantiating a type specific default and recover if the type's
> meta says so. That default could be to issue a NullException. At that
> point you should be able to log null dereferences too.

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 Ruby on Rails. If you're trying to 
render something that's nil you'll get nothing, instead of crashing that 
whole page. Sure, there might be a small icon or similar that isn't 
rendered but that's usually a minor detail. If the page is working and 
main content is rendered that's preferable.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list