if(arr) now a warning

w0rp via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 10 02:27:55 PDT 2015


I think it's worth changing this.

if (arr)

translating to

if (arr.length == 0)

Is immediately obvious for anyone coming from at least a Python 
background. I have implemented my own hashmaps in a similar way. 
For my maps, the length is stored in the map so it can be 
retrieved in O(1) time, and cast(bool) results in map.length == 
0. (This extends also to empty sets.)

If we need a deprecation path, we can do it. We just warn about 
if (arr) for a while, so you are told to use if(arr.length == 0) 
or if (arr.ptr is null) for a while, then we change the behaviour 
in another release.


More information about the Digitalmars-d mailing list