empty arrays and cast(bool): WAT

Jonathan M Davis jmdavisProg at gmx.com
Sat Feb 18 19:17:10 PST 2012


On Sunday, February 19, 2012 04:13:02 Timon Gehr wrote:
> On 02/19/2012 03:24 AM, bearophile wrote:
> > Timon Gehr:
> >> Is there any reason for empty arrays to evaluate to true? This is very
> >> bug prone.
> > 
> > Related?
> > http://d.puremagic.com/issues/show_bug.cgi?id=4733
> > 
> > Bye,
> > bearophile
> 
> Roughly. I want it to be allowed, but to test the length instead of ptr.

That would potentially break code. It also makes arrays less consistent with 
other types that can be null, but the weirdness with [] == null already does 
that on some level.

My general take on it is that you should just be aware that you need to use 
arr.empty when you mean empty and arr !is null when you mean null. So,

if(arr)

is the kind of code that should just be avoided with arrays.

- Jonathan M Davis


More information about the Digitalmars-d mailing list