Nullable trilogy Part I: why not just SQL?
Luca Bolognese -This is the first of a weekly three part serie of posts about Nullable
- Why not just use SQL semantics for null?
- Why null == null doesn’t imply null >= null and null <= null?
- Why inside a generic class with a type parameter t the expression t == null will return false, when t is a nullable type and the value of it is null.
Let’s start from the first question as the answer is shorter. We’ll get to the other two in the coming weeks.
The first question relates to the reason not to have the same semantics as SQL for relational operators. The SQL semantics have been commonly referred to as three-value logic where null == null returns null. Introducing such logic in the C# language would be problematic. The main reason is that the language already contains the concept of null for reference types and it does have the programming languages traditional two-value logic where null == null returns true.
Granted that we cannot change this definition, then the addition of three-value logic just for some types would be confusing. We would need, for example, to create a new NullableString class to be able to apply three-value logic operators to it. More generally, the presence in the same code of two value logic and three value logic operators would make the code quite difficult to write, read and maintain.
Tags
- CSHARP
2 Comments
Comments
aBlogByGus
2005-01-21T04:47:00ZIf the mixture of the word ‘nullable’, question marks, and C# are interesting to you then you you might want to check out the blogs of a couple of my peers: Peter (C# Compiler Dev lead) and Luca (C# Compiler…
Luca Bolognese s WebLog Nullab
2009-06-09T22:17:56ZPingBack from http://toenailfungusite.info/story.php?id=8450