Parameter is null by default. No value is given. Code says it is not null.

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 9 08:04:47 PDT 2015


On 4/9/15 9:32 AM, Adam D. Ruppe wrote:
> Don't use string == null, it is true for empty strings since null and an
> empty string are almost interchangable.

I think this is not good advice. Comparing string to null is perfectly 
fine with ==. It's fine *because* null and empty strings are the same 
thing, so comparing against null is essentially comparing against an 
empty string.

> You can try if(string is null) - is instead of ==. Though usually in D,
> I just if(string.length == 0) and treat empty and null the same way.

This is likely not what you want, it's generally not important where a 
string is located.

Note that the "bad" behavior (which was just fixed BTW) is if(somearr), 
which used to mean if(somearr.ptr), and now it's a compiler error.

-Steve


More information about the Digitalmars-d-learn mailing list