3 ms·
Often, an instance of a class represents a mathematical entity (vector, matrix, imaginary number, mathematical set, et al) where less than might be a fundamenta
by angelbob 11y ago
Often, an instance of a class represents a mathematical entity (vector, matrix, imaginary number, mathematical set, et al) where less than might be a fundamentally reasonable operation, especially in some specific context.
His example is using it as an angle, where comparing two of them is conceptually pretty sensible.
If you pretend it's a structure, sure, you'll need to extract primitive data types out of it before doing anything with it. But if you want it to behave as a higher-level abstraction, reimplementing less-than (say, for comparing the vector magnitude) at every call site isn't great.
- philh 11y ago(This is completely beside the point.) > comparing two of them is conceptually pretty sensible. Well, there are a bunch of sensible ways to do it, depending what the angle represents. You might not want to privilege any of them over the others directly in the class. Is it a point on the unit circle? It doesn't make much sense to compare (sqrt(2), sqrt(2)) to (-1, 0). Is it an angular distance to travel from point A to point B? Then you want 355 and -5 to both be less than 10. Is it an amount that a screw has to be rotated? Then you can't take mods, so 720 > 360 > 0. Do you have a robot that can only turn anticlockwise? Then maybe 5 < -10 < 355. This is the comparison implied by the implementation in TFA (self.degrees = degrees % 360), but it's pretty obscure.