if(arr) now a warning

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 29 10:47:14 PDT 2015


On Wednesday, 29 April 2015 at 04:38:12 UTC, Steven Schveighoffer 
wrote:
> FYI, Andrei and Walter are reversing this change barring any 
> new evidence it's helpful to people. Please speak up if you 
> disagree.
>
> https://github.com/D-Programming-Language/dmd/pull/2885#issuecomment-97299912
>
> -Steve

I don't have precise number to show, but I've been bitten by if 
(arr) doing null check rather than length check more than once.

The most problematic part of it is that it is frequent to have 
empty slice having a null pointer, so the code is likely to pass 
testing, while not doing what you expect it to do, and will break 
later in some bizarre way.

More generally, it is a identity vs equality problem. Slices have 
a semantic where equality is not identity ( == is different than 
is ) so the current behavior is inconsistent.


More information about the Digitalmars-d mailing list