« Negative Testing | Main | SWT vs. Swing comes full circle »

Null Handelers and Null References

Stephen Colebourne has published two interesting ideas that I would like to see make it into the next JDK, Null-Ignore Invocation and Null-Handlers.

The first one isn't new, Groovy has Null-Ignore Invocation but calls it Safe Navigation. The syntax Stephen proposes is to use the Sharp Hash as an operator. i.e. foo#bar() . But I much prefer the Groovy way to do it, foo?.bar() . The ? part of the operator implies to my English-centric mind that there is some question as to whether or not it will be called, and the the dot shows it is a feild or method reference.

The second idea I think is the most interesting, that of a Null handler. This is a similar Idea I came up with while daydreaming in my sophomore Data Structures classes nearly 10 years ago, but I never wrote it down or published it because I thought I'd be laughed out of academia. That was when I thought it wasn't going to take me 13 years to get a B.S., just 8 years.

The idea to me is also very elegant as well in it's implementation. I am sure there are comments that can be made about it obscuring real values of fields. And it will need to be used judiciously (as in likely not in the java.util collections framework). But it can speed up alot of standard error checking. The best part IMHO is that null handlers are they are only called when safe navigation is invoked. The programmer intended for strangeness to happen when the values are null.

This is one of the first real innovations in a while that Java can do that doesn't just steal from another language (not that it's bad, but all the time?) Too bad its coming from outside of the Ivory walls of Sun. Even with OpenJDK it's going to have to fight it's way through the JCP process to get canonized.

About

This page contains a single entry from the blog posted on January 11, 2007 8:34 AM.

The previous post in this blog was Negative Testing.

The next post in this blog is SWT vs. Swing comes full circle.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33