#18305: Element comparison for Python classes
----------------------------------+------------------------
       Reporter:  vdelecroix      |        Owner:
           Type:  enhancement     |       Status:  new
       Priority:  major           |    Milestone:  sage-6.7
      Component:  coercion        |   Resolution:
       Keywords:                  |    Merged in:
        Authors:                  |    Reviewers:
Report Upstream:  N/A             |  Work issues:
         Branch:                  |       Commit:
   Dependencies:  #17890, #18303  |     Stopgaps:
----------------------------------+------------------------

Comment (by vdelecroix):

 Replying to [comment:1 jdemeyer]:
 > I think in general, rich comparisons (both Cython's `__richcmp__` and
 Python's `__eq__` and friends) should be discouraged in favour of `_cmp_`,
 because the latter needs coercion only once. Only for more complicated
 types where rich comparisons cannot be implemented in terms of `__cmp__`
 (intervals for example) should rich comparisons be used.
 >
 > Do you agree?

 Partly. I agree that if `_cmp_` is doable '''and''' cheap then it is
 preferable. But
  - consider lists (or words or sequences), you have a cheap test to check
 whether they are different: comparing the length. So in that case, you
 might want to use it before comparing items one by one for getting the
 lexicographic ordering.
  - there are elements where equality makes sense but not comparison.
 `_richcmp_` can handle that but not `_cmp_`. In such case I would
 implement `_richcmp_` and raise an error if the operator is not `Py_EQ` or
 `Py_NE`.

 And I am not sure that I understand why `_cmp_` needs less coercion than
 `_richcmp_`.

--
Ticket URL: <http://trac.sagemath.org/ticket/18305#comment:2>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to