Why is array truth tied to .ptr?

0ffh frank at frankhirsch.youknow.what.todo.net
Sun Dec 9 22:49:18 PST 2007


Bill Baxter wrote:
> Here's a little test program: [...] So why does the simplest check
> 
> if(array) { ... }
> 
> tell us b) ?

Hmmm... bad luck?

> [...]  But I think Python's way makes a lot more sense than D's way.  So
> it's hard to remember that the simple and clear   if(array)  is almost
> always a bug waiting to happen.

While I'm not used to this shorthand (as I don't regularly meddle in things
Pythonic), I surely could get so quite quickly. I like it. ++votes

I think D's current behaviour makes little sense indeed, as an array is not
just another reference type or object, but something special.
If there was a built-in type "set" in D, I'd expect it to be true when it's
not empty. Same goes for the array type.

regards, frank



More information about the Digitalmars-d mailing list