string <-> null/bool implicit conversion

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 21 07:34:49 PDT 2015


On 8/21/15 10:12 AM, Jonathan M Davis wrote:

> I know full-well that that's what you're doing, but that's not what your
> average programmer is going to expect. Anyone not intimately familiar
> with the ins and outs of D's arrays - or even a D programmer who's not
> paying really close attention - is likely to think that arr != null is
> checking whether the array is null - not whether the array is empty. And
> if I see code like that, I'm going to assume that the programmer who
> wrote the code really wanted was !is null but either made a mistake or
> didn't understand the difference between !is and != in this context.

This is a very bad assumption. null is just a name for a pre-defined 
empty array, perfectly legal to compare with.

Whenever I see "arr is ...", I would consider that to likely be a 
mistake warranting further investigation. Because an array is synonymous 
with its elements, not it's pointer. There obviously are cases where the 
pointer value is important, but very very rarely do you care that an 
array's pointer *and* it's length are identical. != does not warrant the 
same scrutiny, because it doesn't care about the pointer value.

-Steve


More information about the Digitalmars-d mailing list