Sunday, September 7, 2008

Null Coalescing

I like to think that I have a decent understanding of the C# language, so when I found out that there was an operator that I didn't know about I was shocked. There are some operators that I don't use a whole lot (%=, >>=,<<=) but one that I had no idea about, I was shocked. ??, the null coalescing operator.



var y = a??b;



y is a if a is not null, if a is null then y is b.

Straight froward enough, and fairly usefully. I found two usages for it the first day I learned about it. So I took a quick poll around the workplace, and it turns out that ?? wasn't known by anyone I worked with. So why is it, it usefully and easy to use, it isn't new to 3.0, so the only thing left is that it doesn't have a good name.


Null coalescing sounds like something a printer does. "Question mark question mark" is about 4 syllables too long. So from the references guide
some choices might be "quiz quiz", "query query" or "button hook hunchback". But I suggest that we standardize on "huh what". It might cause confusion at first in code reviews, but I think at 2 syllables, and some flare it is the best choice. I am going to start the movement to standardize on the "huh what" nomenclature, I hope you will help me out.

0 comments: