On Wednesday, April 18, 2012 23:52:29 Andrej Mitrovic wrote:
> On 4/18/12, Jonathan M Davis <[email protected]> wrote:
> > that is null == "".
> 
> Wow, I don't understand this, why is comparison with null allowed with
> the equals operator for strings?
> 
> import std.stdio;
> 
> class Foo { }
> void main()
> {
> Foo foo;
> writeln(foo == null); // compile error, as it should be
> writeln("" == null); // true (why is this allowed?)
> writeln("" is null); // false
> }
> 
> Shouldn't the second call be illegal? That would remove ambiguities
> between null strings and empty strings afaict.

It's allowed for arrays in general. Any array whose length is zero is equal to 
another array whose length is zero, and null arrays have a length of 0. [] is 
actually identical to null (though "" isn't). So, null == "" works and is 
true. Personally, I think that it's a serious design flaw in the language - I 
think that null and empty are two different concepts which should never be 
conflated - but that's not how it works. Unfortunately, there's really no 
chance that that's going to be changed at this point.. Here's a related 
enhancement request:

http://d.puremagic.com/issues/show_bug.cgi?id=6346

- Jonathan M Davis

Reply via email to