Why is array truth tied to .ptr?

Janice Caron caron800 at googlemail.com
Mon Dec 10 00:13:00 PST 2007


On Dec 10, 2007 2:01 AM, Bill Baxter <dnewsgroup at billbaxter.com> wrote:
> BTW, if someone does feel the current behavior is more rational or
> functional in some way, then I'd love to hear it.  Perhaps it's my
> familiarity with Python, but I just don't get why you'd want if(array)
> to mean anything other than if(array.length).

Personally, I'd prefer if(array) to fail to compile, because I don't
like the idea of implicit conversions to bool. That would force you to
say what you mean - i.e. either

    if (array.length == 0)

or

    if (array is null)

I suspect the current behaviour really means

    if (array.ptr == null && array.length == 0)

which is not entirely unreasonable. Certainly, in the case of strings
(as special type of array) the current behaviour allows one to
distinguish between an unassigned string and an empty string - which
is occasionally desirable.



More information about the Digitalmars-d mailing list