Dan Byström’s Bwain

Blog without an interesting name

More on nulls

Posted by Dan Byström on April 19, 2005

I’ve previously written a couple of blog posts on an idea of mine: the possibility to have language support for avoiding null reference exceptions.

I had planned to close the matter down in an article claiming that a “with” keyword could be implemented in C# with the ability to take a different path when the “with”-expession couldn’t be evaluated because a null reference exception would occur trying to do so.

Example:

with ( Order order = a.b.c.d.e )
{
    ...
}
else
{
   // either a or b or c or d or e is null and therefore
   // it would be pointless to enter the "with" block
}

Well, now it turns out that I’m not the only one having felt the need for something like this. It is implemented in the Cω research language:

  Cω takes this one step further with the behavior of returning null instead of throwing a NullReferenceException on accessing a field or property of a nullable type whose value is null.

I knew it was a good idea!!! 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: