[Issue 6346] Make == null a warning for arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 18 13:48:36 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6346



--- Comment #3 from Jonathan M Davis <jmdavisProg at gmx.com> 2011-07-18 13:43:18 PDT ---
Well, that's why I said warning rather than error. But I would consider it bad
practice to use == null anywhere with arrays. I'm automatically go to look at
it and wonder whether the programmer really meant is null (and they probably
did). And since I'd expect most code to import std.array if it's doing much
with arrays at all, I'd fully expect it to have access to empty. And while
arr.length == 0 is not as short as arr == length, it's far less error prone. I
think that the used of arr == null implies a fundamental misunderstanding on
the part of the programmer using it. Now, maybe they do understand that it's
the same as arr.length == 0 or arr.empty, but the odds are so high that they
really meant is null that I do _not_ think that code should be using == null.
If you're talking about "code smells" as Bearophile likes to, arr == null
_definitely_ smells. Sure, it _might_ be that it does what the programmer
intended, but odds are that it doesn't.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list