4 ms·
So, which is the case? (0) Python provides a compound value abstraction, but this abstraction leaks, because we can distinguish between multiple representation
by catnaroek 10y ago
So, which is the case?
(0) Python provides a compound value abstraction, but this abstraction leaks, because we can distinguish between multiple representations of the same compound value.
(1) Python doesn't provide a compound value abstraction.
With a few exceptions (e.g., garbage collection, which pretends memory is infinite, even though it's not), I tend not to consider so-called “leaky abstractions” actual abstractions, but if you know of a good reason to do otherwise, please tell me.
- dragonwriter 10y agoPython provides a value abstraction that includes (but is not distinct for) compound values. It also provides an independent mechanism for examining physical (rather than logical) identity -- which is object identity; for all compound values (and all but a very narrow subset of simple values) there is no guarantee that the logical identity of values is equivalent to physical/object identity. I don't see that this makes the value abstraction "leaky", though; for values, value identity is tested by equality. For objects, equality tests object equality but not object identity. Because Python is an "everything is an object" language, you can also test object identity for values, but for values in general there is no defined relationship between object identity and value identity, so this has no defined general logical (as opposed to physical) meaning for value types. (There are some values which are defined to also be singleton objects so that value and object identity are equivalent for these values; but that's a feature not of the value abstraction in Python but of the value-object mapping in Python.) So I don't see the value abstraction itself as leaky. OTOH, I'd probably be happier if Python had (whether it was "is" or something else) a clean logical identity test operator.
- catnaroek 10y agoThis simply doesn't make sense. It violates the indiscernibility of identicals, which is one of the cornerstones of Western logic. I can accept different opinions on several matters (e.g., the extent to which using objects is a good idea), but throwing logic out of the window is just too much.
- sevensor 10y agoI would argue that, because Python requires its users to reason about storage and interpreter state, we shouldn't consider (a,b,c) and (a,b,c) identical under is unless they're aliases for the same structure in memory. I'm not sure I understand dragonwriter's idea for a third equality operator, however. Isn't == adequate for that purpose? By the way, I'd like to thank both catnaroek and dragonwriter for an excellent discussion; this sort of thing is why I come to HN.
- catnaroek 10y ago> we shouldn't consider (a,b,c) and (a,b,c) identical under is unless they're aliases for the same structure in memory. Which is the entirety of my point.
- pdonis 10y ago> It violates the indiscernibility of identicals, which is one of the cornerstones of Western logic. Oh, please. Python isn't violating any principles of Western logic. It's only violating your idiosyncratic insistence that there can only be one in-memory representation of any immutable value. Python does this for some types but not for others. Yet computers manage to run Python just fine, Western logic notwithstanding. If you want to argue that Python ought to change its implementation to guarantee that, for example, any two references to the tuple (1, 2, 3) must refer to the same in-memory representation (so the 'is' operator would always return True), because that would save memory, or make the runtime faster, or whatever, that's fine. Then we can talk about the tradeoffs involved, such as increasing complexity in the interpreter code. But trying to claim that Python is violating "one of the cornerstones of Western logic" is just too much.
- catnaroek 10y ago> It's only violating your idiosyncratic insistence that there can only be one in-memory representation of any immutable value. I never said this! There can be multiple representations of the same value. For example, the same ordered set may be represented as two distinct red-black trees, balanced differently. Values are different from their memory representations. Different memory representations of the same value are okay. Branching on the difference is not. Of course, to hide representation differences from users, you need abstract data types [0], and, sadly, Python doesn't have these. [0] https://www.cs.cmu.edu/~rwh/introsml/modules/sigstruct.htm https://www.cs.cmu.edu/~rwh/introsml/modules/sigstruct.htm > If you want to argue that Python ought to change its implementation to guarantee that, for example, any two references to the tuple (1, 2, 3) must refer to the same in-memory representation (so the 'is' operator would always return True), because that would save memory, or make the runtime faster, or whatever, that's fine. I never said this either. I said that it should be a valid optimization, not that implementations absolutely have to do it. As things stand now, it's not a valid optimization, because it would break existing programs. In actuality, I don't care much about the optimization itself. However, it's a good benchmark for assessing whether Python has compound values. Values can be deduplicated, because they may be represented more than once. Objects can't be deduplicated, because by definition an object exists exactly once in memory. > But trying to claim that Python is violating "one of the cornerstones of Western logic" is just too much. It seems appropriate to me. But, to be clear, what I was claiming violates the indiscernibility of identicals is dragonwriter's explanation, not Python itself. A simple explanation that doesn't violate the indiscernibility of identicals is to admit that Python doesn't have compound values. Which takes us back to square one [1]. [1] https://news.ycombinator.com/item?id=12358968 https://news.ycombinator.com/item?id=12358968
- pdonis 10y ago> I'd probably be happier if Python had (whether it was "is" or something else) a clean logical identity test operator. Isn't that what == is?
- catnaroek 10y agoSomehow Python lets you distinguish “logically identical” things, though.
- pdonis 10y agoIf you're interested in properties other than logical identity, yes.
- catnaroek 10y agoBy definition identity checking is the finest-grained distinction you can make between things. If two things are identical, they can't possibly be different in any way. This is what philosophers call the “indiscernibility of identicals”, and, if it sounds like a tautology, it's because it is!
- pdonis 10y ago> By definition identity checking is the finest-grained distinction you can make between things By your definition, perhaps. The rest of us don't always use the word "identity" with this meaning. And since you don't own the English language, you don't get to tell the rest of us how to use words. > If two things are identical, they can't possibly be different in any way. Then by your definition, two Python tuples (1, 2, 3) are not identical. Which says absolutely nothing about how I can write programs using them, or what concepts of "identity" the operators in those programs can implement. > This is what philosophers call... We're talking about programming here, not philosophy.
- catnaroek 10y ago> Which says absolutely nothing about how I can write programs using them, I can write a program that treats all Python objects identically, by simply doing nothing. That doesn't make all Python objects actually identical. > We're talking about programming here, not philosophy. Programming is applied logic, which is a branch of philosophy.