Confused Programmers Question Code... (C# 2.0 and the nullable syntax)
It is odd when a programming language feature uses such a powerful natural language construct. The question mark (?) denotes so much meaning in terms of understanding, insight, and curiosity. To use such a symbol to mean something quite different, in the case of nullable types in C#, is very odd to me. Take the following code:
int? foo = null;
The above seems almost incomplete, as if the programmer didn't know exactly what they were doing, and not that the type is actually a larger construct that allows for the absence of value. I have to admit, it is a great shortcut, but readers of the language will have to be curious about why the programmer is questioning his use of variable type. Even worse, they are assigning null to an integral type, how confusing.
Even more confusing is the allowance of a nullable reference type, however, the compiler does give due warning for this. However, to note there could be cases where the lack of a value has different meaning than a null value. The lack of a value might mean unset or untried, a kind of quantum concept for not having investigated the possibilities of a variable. A null value on the other hand would clearly represent a lack of data after inspection. Two states at once and the possibility of two different types of return values. Note: This is NOT possible since there is no way to set the value to null and have the HasValue return true. It would have just been nice to have in some strange world far, far away
Now, to think about the construct in terms of a question, “Is the value present or not?”, would be appropriate. At least they didn't use an exclamation point (!), because the last thing we need is to get spuriously excited by writing our code. I already have a twitch from the coffee, don't compound that with short bouts of value type excitement.
Now, taking that in stride, would the exclamation point provide a meaningful construct? Well, an exclamation implies excitement, something more, something greater, enhancement. We often use it to enhance what we are saying. The difference between “That's great Bob” and “That's great Bob!” is unobvious at times in written form, but the spoke differences are extreme. After all, a nullable value type is really something more, but only slightly more, than the original value type. So in this case an exclamation point would be just as valid a choice to denote nullable types.
Well, you probably find it strange the reading code may evoke some sort of natural language emotional reponse. However, I know a number of programmers that took the length of a comment, for instance, to mean something more than what was implied. Short sentences tend to be imperative when read making them seem absolute. When documenting code you often write few words to explain what you were doing. You aren't setting anything in stone, but the appearance upon reading is there.
Well, while you get angry at short comments, hopefully that gets balanced out by a nagging, questioning feeling coming from all of the extra question marks.