On Fri, Sep 26, 2014 at 02:01:22PM -0400, Steven Schveighoffer via 
Digitalmars-d-learn wrote:
> On 9/25/14 8:24 PM, AsmMan wrote:
[...]
> >It made me a bit confusing. How is the implementation of string
> >comparasion in D? (if someone could point to actual code used in
> >these comparasion would be really great otherwise I'll check out
> >assembly output, maybe) in no language I know of (including C#)
> >"" == null is true
[...]

In D, it's generally a bad idea to compare arrays with null, unless
you're prepared to handle a lot of implementation-specific details.
Instead, you should check .length, if it's 0, the string is empty,
otherwise, it's not.

If you need to distinguish between an empty string and null, you might
want to consider using std.typecons.Nullable instead. It's slightly more
verbose, but makes the intent of the code clearer and may lead to more
maintainable code.


T

-- 
One disk to rule them all, One disk to find them. One disk to bring them all 
and in the darkness grind them. In the Land of Redmond where the shadows lie. 
-- The Silicon Valley Tarot

Reply via email to