3 ms·
1. Encapsulation (arguably the whole purpose of creating such a class in the first place). 2. Would you think it's reasonable for a class to implement equality
by exogen 11y ago
1. Encapsulation (arguably the whole purpose of creating such a class in the first place).
2. Would you think it's reasonable for a class to implement equality ==, so it can tell you if it's equal to another instance of the same class? Then why not ordering?
3. Take Python's set type as a useful example. A < B tells you whether A is a subset of B, A | B returns the union, etc. All very handy.
- cballard 11y agoI disagree with 3, a subset is not "less than" the superset. Sets are equatable, but they're not comparable. A named function or a different operator would be preferable.
- dragonwriter 11y agoThe set of sets is, itself, a strictly partially ordered set by the "is a proper subset of" relation (and a non-strict partially ordered set by the "is a subset of" relation); if Python's < and > operators are viewed as generic strict ordering operators (and those symbols are, outside of Python, conventionally used for both strict total orders like those on reals and strict partial orders), then their use with sets for the strict partial order defined by the "is a proper subset of" relation is quite natural.