Checking if a string is null
Max Samukha
samukha at voliacable.com.removethis
Wed Jul 25 10:27:27 PDT 2007
On Wed, 25 Jul 2007 15:30:10 +0100, Regan Heath <regan at netmail.co.nz>
wrote:
>I am a little puzzled by the fact that:
>"Identity Expressions" include ("is", "!is")
>"Equality Expressions" include ("==", "!=", "is", "!is")
>Why do "is" and "!is" exist in both equality and identity?
>From "Identity Expressions: "For operand types other than class
objects, static or dynamic arrays, identity is defined as being the
same as equality." That's the reason, I guess.
>
>> But in current D empty arrays can have a null identity (even if they
>> don't allway have), so you can't use 'is' to try do distinguish null
>> arrays from empty arrays. Thus effectively they are semantically the
>> same in current D.
>
>I understand what you're saying now.
>
>Given that null and "" have different ptr values, they therefore "refer
>to different array elements" and "is" should distinguish them.
>
>But, in current D implementation the .dup function isn't distinguishing
>the cases and is instead duplicating "" resulting in null and therefore
>preventing further distinction of the 2 cases.
>
>This is similar to the behaviour where setting length to 0 used to free
>the data pointer, turning an empty array into a null one.
>
>So, this definately needs fixing I reckon.
>
>Regan
IMO, your proposal makes sense. I think, "" == null will be a rich
source of confusion for newcomers. OTOH, I can live with the current
implementation after it has been explained. Thanks to all of you.
More information about the Digitalmars-d
mailing list