If I had the time machine for comparisons
On Wed, Oct 12, 2011 at 11:18 PM, Guido van Rossum <guido@python.org> wrote:
(I'm also -1 on adding ordering comparisons; there's little disagreement on that issue.)
If I had a time machine, I would allow comparisons to return "unordered" as well. Right now, objects are comparable or not based strictly on the type, even though comparison is inherently about the values. I think that range(3) < range(10) is obviously true, even though it isn't clear whether or not range(3, 15, 2) < range(7, -8, -1) is true. Here we err by not allowing the first comparison; other objects (like dicts) we err by forcing an arbitrary ordering. -jJ
On Thu, Oct 13, 2011 at 7:06 AM, Jim Jewett <jimjjewett@gmail.com> wrote:
On Wed, Oct 12, 2011 at 11:18 PM, Guido van Rossum <guido@python.org> wrote:
(I'm also -1 on adding ordering comparisons; there's little disagreement on that issue.)
If I had a time machine, I would allow comparisons to return "unordered" as well. Right now, objects are comparable or not based strictly on the type, even though comparison is inherently about the values.
I think that
range(3) < range(10)
is obviously true, even though it isn't clear whether or not
range(3, 15, 2) < range(7, -8, -1)
is true.
Here we err by not allowing the first comparison; other objects (like dicts) we err by forcing an arbitrary ordering.
Have you used Python3 lately? It doesn't allow dict ordering. In general Python expresses unordered by raising an exception (often TypeError). Even though range(1) is "obviously" < range(2), there are so many unobvious cases that supporting this one special case isn't worth it. -- --Guido van Rossum (python.org/~guido)
On 10/13/2011 10:06 AM, Jim Jewett wrote:
I think that
range(3) < range(10)
is obviously true
Based on what property? Is that because: a) len(range(3)) < len(range(10)) b) max(range(3)) < min(range(10)) c) ((min(range(3)) < min(range(10))) and (max(range(3)) < max(range(10))) I guess your argument is that in this degenerate case, all of these properties are true so it is "obviously true". Personally, if I can't pin-point the exact reason that "x < y", then it's not obvious even if for every definition of "<" I can come up with it is a true statement, because there is not one obvious definition that is true. In other words, I don't know what "x < y" means for ranges in general so I can't reason about it in general, therefore this special case is not useful or obvious. In the absence of explicit arguments to the "<" operand, I would be baffled as to what to expect as the result. However, I can understand the desire to test for range equality, and the definition for that is significantly more obvious. -- Scott Dial scott@scottdial.com
participants (3)
-
Guido van Rossum
-
Jim Jewett
-
Scott Dial