February 12, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=948

           Summary: operatoroverloading.html - Rationale section is both out
                    of date and incomplete
           Product: D
           Version: 1.005
          Platform: All
               URL: http://www.digitalmars.com/d/operatoroverloading.html
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: www.digitalmars.com
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: smjg@iname.com


At the end of the "Overloading <, <=, > and >=" section is a "Rationale", which states:

"For some objects, testing for less or greater makes no sense. For these, override opCmp() with: " [...]

There are two things wrong with this (besides the fact that that code would now trigger a "statement is not reachable" warning in DMD, but that's irrelevant):

- The instruction to override opCmp is a leftover from when the default Object.opCmp compared the memory address.  Nowadays, Object.opCmp already throws an error, so there's no point overriding a class's opCmp as an extra.

- This has been briefly mentioned before but nothing done about it.  On reading just above it that "every class object has a opCmp()", people will look for an explanation of _why_ opCmp should be defined for every class.  Instead, the average reader is treated to what reads as an argument _against_ this, namely "For some objects, testing for less or greater makes no sense."

I propose the following rewrite of the bullet points in this section to address both problems:

- Testing for equality can sometimes be a much more efficient operation than
testing for less or greater than.
- Having opCmp defined in Object makes it easier to implement associative
arrays and sorting efficiently.
- For some classes, testing for less or greater makes no sense.  The default
Object.opCmp throws an error at runtime to indicate that the programmer has not
defined an opCmp for the class being used.


-- 

March 30, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=948


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #1 from bugzilla@digitalmars.com  2007-03-29 19:05 -------
Fixed DMD 1.010


--