On May 6, 2020, at 05:22, Richard Damon <rich...@damon-family.org> wrote:
> 
> In my mind, tuples and lists seem very different concepts, that just
> happen to work similarly at a low level (and because of that, are
> sometimes 'misused' as each other because it happens to 'work').

I think this thread has gotten off track, and this is really the key issue here.

If someone wants this proposal, it’s because they believe it’s _not_ a misuse 
to use a tuple as a frozen list (or a list as a mutable tuple).

If someone doesn’t want this proposal, the most likely reason (although 
admittedly there are others) is because they believe it _is_ a misuse to use a 
tuple as a frozen list.

It’s not always a misuse; it’s sometimes perfectly idiomatic to use a tuple as 
an immutable hashable sequence. It doesn’t just happen to 'work', it works, for 
principled reasons (tuple is a Sequence), and this is a good thing.[1]

It’s just that it’s _also_ common (probably a lot more common, but even that 
isn’t necessary) to use it as an anonymous struct.

So, the OP is right that (1,2,3)==[1,2,3] would sometimes be handy, the 
opponents are right that it would often be misleading, and the question isn’t 
which one is right, it’s just how often is often. And the answer is obviously: 
often enough that it can’t be ignored. And that’s all that matters here.

And that’s why tuple is different from frozenset. Very few uses of frozenset 
are as something other than a frozen set, so it’s almost never misleading that 
frozensets equal sets; plenty of tuples aren’t frozen lists, so it would often 
be misleading if tuples equaled lists.

—-

[1] If anyone still wants to argue that using a tuple as a hashable sequence 
instead of an anonymous struct is wrong, how would you change this excerpt of 
code:

    memomean = memoize(mean, key=tuple)
    def player_stats(player):
        # …
        … = memomean(player.scores) …
        # …

Player.scores is a list of ints, and a new one is appended after each match, so 
a list is clearly the right thing. But you can’t use a list as a cache key. You 
need a hashable sequence of the same values. And the way to spell that in 
Python is tuple.

And that’s not a design flaw in Python, it’s a feature. (Shimmer is a floor wax 
_and_ a dessert topping!) Sure, when you see a tuple, the default first guess 
is that it’s an anonymous struct—but when it isn’t, it’s usually so obvious 
from context that you don’t even have to think about it. It’s confusing a lot 
less often than, say, str, and it’s helpful a lot more often.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/F65FI2QMUOUCD2RVW4APQMNAFALQZFXB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to