"is null" vs "== null"
Søren J. Løvborg
web at kwi.dk
Sun Mar 26 09:31:47 PST 2006
Anders F Björklund wrote:
>> I find it problematic that comparing null-values with the == operator
>> crashes D programs.
>
> Yes, this is problematic and it has been up for discussion before...
>
> Some old threads, for reference:
> 2005
> http://www.digitalmars.com/d/archives/digitalmars/D/21225.html
> 2003
> http://www.digitalmars.com/d/archives/12144.html
>
> But I don't think that the language position on "null" has changed...
Walther wrote (on Fri, 13 Jun 2003):
> So, think of (o==p) with objects as "Compare the contents of object o with
> object p. If either is null, there are no contents, and that is outside
> the
> scope of the == operator's purpose. Therefore, an exception is thrown just
> as if an array bounds were exceeded. If the object references are not
> supposed to be null, then it's a program bug. If the object references can
> be null, then explicitly code what a null reference means.
So == doesn't handle nulls since nulls are defined to be outside the scope
of its purpose.
The question is whether == would be more useful to programmers, if its scope
was extended to include null values.
I'll venture to say that most people will expect that null == null, and at
the very least, it seems that many (most?) people on the NG agree.
Since comparing against null is illegal in the current specification, the
change could be made without affecting existing programs.
Besides Walther, who's already stated his reasons, anyone else who's against
such a change?
> A segfault is viewed as an exception, since it throws one on Windows.
True, I forgot that the Linux compiler merely lacks this functionality.
Søren J. Løvborg
web at kwi.dk
More information about the Digitalmars-d
mailing list