if(arr) now a warning

w0rp via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 10 05:40:25 PDT 2015


On Friday, 10 April 2015 at 10:14:43 UTC, Martin Nowak wrote:
> On Friday, 10 April 2015 at 09:27:56 UTC, w0rp wrote:
>> 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.
>
> That's kind of the roadmap, though we'd need to wait quite a 
> while until we can reuse it.
> I've been thinking about moving std.array.empty to object. Then 
> that could more easily become the replacement idiom.
>
> if (arr) -> if (!arr.empty)
>
> It's much clearer and also what you need to write when you work 
> with ranges.

I like this. I put in a .empty property for the hashmaps and sets 
I wrote which uses .length == 0.

if (arr) is a problem for new D programmers, who will write it 
probably expecting it to be the same as if (arr.length == 0). Any 
struct type in D can behave the same way by implementing an 
overload for cast(bool).


More information about the Digitalmars-d mailing list