On Sun, Oct 13, 2019, 6:12 PM Steven D'Aprano:

> Is that correct though? To the best of my memory, I've never wanted to add
> an item to a list-or-set in 15 years, nor have I seen code in practice that
> does so. I don't think it is "very common"


Really?! I've seen it several times this week. Maybe we mean something
slightly different though.

My real world is looking at some function in an existing codebase that
handles a nested data structure. At some leaf I can tell I'm handling a
bunch of scalars by looking at the code (i.e. a loop or a reduction).

Somewhere far upstream that data was added to the structure. And somewhere
downstream we might do something sensitive to the data type. But right
here, it's just "a bunch of stuff." I rarely see the "bunch" being
genuinely polymorphic, but I also just don't want or need to think about
which collection it is to edit this code.... Except I do if I want to "just
add item".

Moreover, it's not uncommon to want to optimize the upstream choice of
container and need as little refactoring downstream as possible.

But yes, set and list are not generically interchangeable, of course. Maybe
the stuff really needs to have mutables. Maybe it needs to allow repeats.
Refactoring isn't just drop in replacement, and one needs to think of such
issues.
_______________________________________________
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/DYUPIA7HW5LWGKQMIAYRPENDPKSQAEQY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to