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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 18 12:57:02 PDT 2011


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

           Summary: Make == null a warning for arrays
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: jmdavisProg at gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg at gmx.com> 2011-07-18 12:51:46 PDT ---
The correct way to test whether something in null in D is to use is. Using ==
null with strings is doing the same as checking whether their length == 0. This
is _not_ what most people are going to expect. So, if you actually understand
the rules, then the correct way to check for null is is null, and the correct
way to check for empty is to either use length == 0 or std.array.empty. As
such, there is no point in using == and if it's in the code, there's a good
chance that it's a bug.

It appears that there is _already_ such a warning when dealing with classes. I
think that it would be far less error-prone to make the same warning apply to
arrays. I don't think that there is really a reasonable case for use == null in
D at all, so in all cases, it should generate a warning. is null is what
actually checks for null, and there are better, clearer ways to check for empty
with arrays.

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