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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 18 14:51:49 PDT 2011


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



--- Comment #5 from Jonathan M Davis <jmdavisProg at gmx.com> 2011-07-18 14:46:24 PDT ---
In pretty much every other language that I've ever used, null is _not_ the same
thing as empty _ever_. Someone coming from C, C++, Java etc. is going to expect
dynamic arrays to be able to be null. The way that you check for null in all of
those languages is either == 0 or == null (or == NULL or == nullptr). is does
not exist in any other language that I've ever seen. I fully expect programmers
from C, C++, Java etc. to expect == null to be checking whether an array is
null - that is whether is null is true. But it doesn't do that. It checks
whether length == 0.

The fact that an empty array an null are almost synonymous in D is incredibly
bizarre. It simplifies declaring an array and then appending it or setting its
length, but it is _not_ what your average programmer is going to expect coming
from other C-based languages. As such, I expect that == null risks being a
frequent newbie mistake. The only reason it wouldn't be is if not that many
newbies need to or care about checking for null.

The fact that

if(arr)

and

if(arr is null)

don't do the same thing is a related but separate issue, and should probably
also be addressed. But I really think that == null is a problem which is going
to throw off a lot of people. If I see it in code, I'm either going to point it
out or change it (depending on the circumstances). The odds are just too high
that it doesn't do what the programmer intended or that someone else reading
the code will misinterpret what it does.

-- 
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