On 10/13/2019 5:57 PM, Steven D'Aprano wrote:
On Sun, Oct 13, 2019 at 07:20:29PM -0000, Steve Jorgensen wrote:
Failing fast is good, but it is also a very common case to want to add an item to a collection regardless of whether it is set-like or sequence-like.
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", but I would like to see some examples of your code, and third-party libraries, which do this.
On a few occasions I have modified code that used lists to instead use sets. Generally I was porting very old code, before sets were built in, so lists had been used. However, sets were more appropriate when I refactoring. It would have saved me some hassle had lists and sets worked the same way as far as adding members. But I can't say it's very common. I don't think I've ever seen code that wanted to use duck-typing for adding an element/item to a container. I'm sure it exists, but probably is not very common. Eric