Steven D'Aprano wrote:
> On Sun, Oct 13, 2019 at 05:42:21PM -0400, David Mertz wrote:
> > I have definitely hit this difficulty many times. The
> > part of the code that
> > "just puts something in the collection" doesn't need to care conceptually
> > about the kind of collection. Taking the data back out somewhere else more
> > often needs to worry about order, efficiency, concurrency, etc.
> > And that's why I am skeptical that there is "very common" code that 
> doesn't care about whether it has a list or a set. We surely almost 
> always will care when we're taking the data out again, because of 
> ordering and efficiency etc.
> If you require a set for the data-output side, why would you accept a 
> list for the data-input side when you won't be able to use it further 
> on? And vice versa.
> In the absense of any concrete examples demonstrating that this is 
> useful, I think this is an over-generalisation of little practical use.

Having come from Ruby to Python, this seems like an odd statement to me. It 
always felt very natural that there is one way to add something to a simple 
collection, and the distinction between an "array" and a set is irrelevant in 
that regard. Of course, just because I'm used to that as a natural thing 
doesn't make it right for Python.

Thinking about examples, the ones that immediately come to mind are mainly 
collectors — objects passed into a method to record things that will be 
examined afterward by the caller. In those cases, what I'm talking about could 
actually be handled (actually with more versatility) by having the called 
method expect a callable though, since it will only do one thing with the 
object that is passed in. The caller would then pass in `<some-set>.add`, 
`<some.list>.append` in that case (or whatever else is appropriate).

That, of course, is simply a coding pattern and doesn't require any changes to 
the standard lib.

Having said all of that, I have a feeling that there are categories of example 
that I'm not thinking of right now. Maybe others will chime in with such 
examples — or to agree there there are none (or extremely few).
_______________________________________________
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/D3UJTOALVZV524PVWLXTGV2FAIAAF2QG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to