In how many languages is Null not equal to anything not even Null?
在多少种语言中Null不等于甚至没有Null的东西?
7 个解决方案
#1
15
It's this way in SQL (as a logic language) because null means unknown/undefined.
这是SQL中的这种方式(作为逻辑语言),因为null意味着未知/未定义。
However, in programming languages (like say, C++ or C#), a null pointer/reference is a specific value with a specific meaning -- nothing.
但是,在编程语言(例如,C ++或C#)中,空指针/引用是具有特定含义的特定值 - 没有。
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.
两个无关紧要,但两个未知数不是。混淆来自于两个概念都使用相同的名称(null)。
#2
4
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:
在VB6中,表达式Null = Null将产生Null而不是True,如您所料。如果您尝试将其分配给布尔值,这将导致运行时错误,但是如果您将其用作“If ... Then”的条件,则它将表现为False。而且Null <> Null也会产生Null,所以:
In VB6 you could say that Null
is neither equal to itself (or anything else), nor unequal!
在VB6中你可以说Null既不等于它自己(或其他任何东西),也不等于!
You're supposed to test for it using the IsNull()
function.
你应该使用IsNull()函数测试它。
VB6 also has other special values:
VB6还有其他特殊值:
-
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 writeMissing = Missing
. (the test isIsMissing(foo)
) -
Empty
for uninitialized variables. This one does test equal to itself although there's also a functionIsEmpty()
. - ... let me know if I've forgotten one
没有任何对象引用。 Nothing =没有什么是编译错误。 (你应该用“是”来比较它)
缺少未给出的可选参数。它没有文字表示,所以你甚至不能写Missing = Missing。 (测试是IsMissing(foo))
清空未初始化的变量。尽管还有一个函数IsEmpty(),但这个测试确实等于它自己。
...如果我忘了一个,请告诉我
I remember being a bit disgusted with VB.
我记得有点厌恶VB。
#3
3
Oracle is this way.
Oracle就是这样。
SELECT * FROM dual WHERE NULL=null; --no rows returned
#4
3
MySQL has a null-safe equality operator, <=>, which returns true if both sides are equal or both sides are null. See MySQL Docs.
MySQL有一个空安全等式运算符<=>,如果双方都相等或双方都为空,则返回true。请参阅MySQL文档。
#5
2
In C#, Nullable<bool> has interesting properties with respect to logical operators, but the equality operator is the same as other types in that language (i.e., ((bool?)null == (bool?)null) == true).
在C#中,Nullable
To preserve the short-circuited behavior of the short-circuited logical operators, and to preserve consistency with the non-short-circuited logical operators, the nullable boolean has some interesting properties. For example: true || null == true. false && null == false, etc. This stands in direct contradiction with other three-valued logic languages such as ANSI SQL.
为了保持短路逻辑运算符的短路行为,并保持与非短路逻辑运算符的一致性,可空布尔值具有一些有趣的属性。例如:true || null == true。 false && null == false等。这与其他三值逻辑语言(如ANSI SQL)直接矛盾。
#6
2
You can make ruby work that way:
你可以用这种方式制作ruby:
class Null
def self.==(other);false;end
end
n=Null
print "Null equals nothing" if n!=Null
#7
0
In SQL you would have to do something like:
在SQL中,您必须执行以下操作:
WHERE column is NULL
rather than
WHERE column = NULL
#1
15
It's this way in SQL (as a logic language) because null means unknown/undefined.
这是SQL中的这种方式(作为逻辑语言),因为null意味着未知/未定义。
However, in programming languages (like say, C++ or C#), a null pointer/reference is a specific value with a specific meaning -- nothing.
但是,在编程语言(例如,C ++或C#)中,空指针/引用是具有特定含义的特定值 - 没有。
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.
两个无关紧要,但两个未知数不是。混淆来自于两个概念都使用相同的名称(null)。
#2
4
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:
在VB6中,表达式Null = Null将产生Null而不是True,如您所料。如果您尝试将其分配给布尔值,这将导致运行时错误,但是如果您将其用作“If ... Then”的条件,则它将表现为False。而且Null <> Null也会产生Null,所以:
In VB6 you could say that Null
is neither equal to itself (or anything else), nor unequal!
在VB6中你可以说Null既不等于它自己(或其他任何东西),也不等于!
You're supposed to test for it using the IsNull()
function.
你应该使用IsNull()函数测试它。
VB6 also has other special values:
VB6还有其他特殊值:
-
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 writeMissing = Missing
. (the test isIsMissing(foo)
) -
Empty
for uninitialized variables. This one does test equal to itself although there's also a functionIsEmpty()
. - ... let me know if I've forgotten one
没有任何对象引用。 Nothing =没有什么是编译错误。 (你应该用“是”来比较它)
缺少未给出的可选参数。它没有文字表示,所以你甚至不能写Missing = Missing。 (测试是IsMissing(foo))
清空未初始化的变量。尽管还有一个函数IsEmpty(),但这个测试确实等于它自己。
...如果我忘了一个,请告诉我
I remember being a bit disgusted with VB.
我记得有点厌恶VB。
#3
3
Oracle is this way.
Oracle就是这样。
SELECT * FROM dual WHERE NULL=null; --no rows returned
#4
3
MySQL has a null-safe equality operator, <=>, which returns true if both sides are equal or both sides are null. See MySQL Docs.
MySQL有一个空安全等式运算符<=>,如果双方都相等或双方都为空,则返回true。请参阅MySQL文档。
#5
2
In C#, Nullable<bool> has interesting properties with respect to logical operators, but the equality operator is the same as other types in that language (i.e., ((bool?)null == (bool?)null) == true).
在C#中,Nullable
To preserve the short-circuited behavior of the short-circuited logical operators, and to preserve consistency with the non-short-circuited logical operators, the nullable boolean has some interesting properties. For example: true || null == true. false && null == false, etc. This stands in direct contradiction with other three-valued logic languages such as ANSI SQL.
为了保持短路逻辑运算符的短路行为,并保持与非短路逻辑运算符的一致性,可空布尔值具有一些有趣的属性。例如:true || null == true。 false && null == false等。这与其他三值逻辑语言(如ANSI SQL)直接矛盾。
#6
2
You can make ruby work that way:
你可以用这种方式制作ruby:
class Null
def self.==(other);false;end
end
n=Null
print "Null equals nothing" if n!=Null
#7
0
In SQL you would have to do something like:
在SQL中,您必须执行以下操作:
WHERE column is NULL
rather than
WHERE column = NULL