Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In how many languages is Null not equal to anything not even Null?

In how many languages is Null not equal to anything not even Null?

like image 600
cazlab Avatar asked Sep 16 '08 18:09

cazlab


3 Answers

It's this way in SQL (as a logic language) because null means unknown/undefined.

However, in programming languages (like say, C++ or C#), a null pointer/reference is a specific value with a specific meaning -- nothing.

Two nothings are equivilent, but two unknowns are not. The confusion comes from the fact that the same name (null) is used for both concepts.

like image 88
Jonathan Rupp Avatar answered Nov 19 '22 13:11

Jonathan Rupp


In VB6 the expression Null = Null will produce Null instead of True as you would expect. This will cause a runtime error if you try to assign it to a Boolean, however if you use it as the condition of "If ... Then" it will act like False. Moreover Null <> Null will also produce Null, so:

In VB6 you could say that Null is neither equal to itself (or anything else), nor unequal!

You're supposed to test for it using the IsNull() function.

VB6 also has other special values:

  • Nothing for object references. Nothing = Nothing is a compile error. (you're supposed to compare it using "is")
  • Missing for optional parameters which haven't been given. It has no literal representation so you can't even write Missing = Missing. (the test is IsMissing(foo))
  • Empty for uninitialized variables. This one does test equal to itself although there's also a function IsEmpty().
  • ... let me know if I've forgotten one

I remember being a bit disgusted with VB.

like image 28
Hugh Allen Avatar answered Nov 19 '22 11:11

Hugh Allen


Oracle is this way.

SELECT * FROM dual WHERE NULL=null;  --no rows returned
like image 25
Josh Bush Avatar answered Nov 19 '22 12:11

Josh Bush