Skip to content

Distinction NULL vs. ” (empty string) needless in programming and databases

Coming from Delphi to C# I was not happy with the need for string.IsNullOrEmpty(myString) upon every check for an empty string. While I do understand that technical implementation may actually make this distinction, I really cannot se why we would be bothered having to distinguish. This topic has been discussed over and over, and it seems most developers support the idea that an empty string is actually not the same as a NULL value.

I beg to differ, for more reasons:

  • A string is the only data type that actually has a natural NULL value - an empty string. When you may specify a middle name, leaving it empty means "no value".
  • A major database vendor - Oracle - handles empty string as NULL without this being problematic to the world of RDBMS modellers, and Delphi Pascal (Version 2 ->) programming language implements an empty string as a null pointer behind the scene with very few developers ever noticing. I never heard anyone complaining about this.
  • For other data types, a user control easily shows NULL value: A checkbox being grayed out, a radio group with no selection, a blank numeric input field. How would you represent a null value in a text box ? Showing a grayed <null> or <empty> when actually NULL, and just blank if non-NULL ? Good luck with explaining users the difference....

The only case where you would actually need to differ would be when using string values in a database column with UNIQUE constraint; But actually treating an empty string as NULL solves this problem.

This behind-the-scene handler prevalent in both Oracle and Delphi does of course add a few operations every here and there (=more clock ticks), but I believe in most cases it would be desirable.

When talking of strange topics in IT world - did you know that in Firebird database, 0 <> -0 ?

Have a nice day !