Monday, August 22, 2005

Nullifying C#?

Nullable Types "Support for nullability across all types, including value types, is essential when interacting with databases, yet general purpose programming languages have historically provided little or no support in this area."

Nulls in a database indicate unknown or some other semantic for the value being missing. Missing Information Withot Nulls: "But NULL isn’t a value of type VARCHAR(20), nor of type DECIMAL(6,0)." The decomposition of the tables shown in this looks very much like RDF (page 15 even talks about triple operations).

An example of the syntax:
int? nFirst = null;
int Second = 2;
nFirst = null; // Valid
Second = nFirst; // Exception, Second is nonnullable.

Nulls not missing anymore "The outcome is that the Nullable type is now a new basic runtime intrinsic. It is still declared as a generic value-type, yet the runtime treats it special. One of the foremost changes is that boxing now honors the null state. A Nullabe int now boxes to become not a boxed Nullable int but a boxed int (or a null reference as the null state may indicate.) Likewise, it is now possible to unbox any kind of boxed value-type into its Nullable type equivalent."

Related: Avoiding Null in C#, Stopping nulls in Java, Null Object Pattern, Null Considered Harmful, Nulls and the Relational Model, Clean design solution for NULLs with Java primitives, Date and Pascal on RDF and Relational Algebra.

While you can argue whether C# should support NULLs in databases, it does seem like a fairly pragmatic decision based on the current state of the industry.

No comments: