4 ms·
This is true, and I'm sure Guido is fully aware of it, but it's also not entirely relevant to what he was saying. Regardless of inheritance, interfaces, and duc
by kyllo 13y ago
This is true, and I'm sure Guido is fully aware of it, but it's also not entirely relevant to what he was saying. Regardless of inheritance, interfaces, and duck typing, the explicit classes of the objects still do matter.
Yes, the list of [1,'A',2,'B',3,'C'] is really after all just a list of [Object, Object, Object, Object, Object, Object]. And the list itself is also just an Object.
But the explicit classes of the elements of the list are different ([int,str,int,str,int,str]), and often that actually does matter for the use case, because int and str have different interfaces, and "adding" ints means something different than "adding" strs for example. It really just depends on what you're going to do with that data, and I think Guido was also talking in terms of the idiomatic use cases for the different data structures.
- dragonwriter 13y ago> This is true, and I'm sure Guido is fully aware of it Well, yeah. I'd be kind of stunned if he wasn't. I was making a note qualifying the examples that were given in isolation, not questioning the basic premise. > Regardless of inheritance, interfaces, and duck typing, the explicit classes of the objects still do matter. Whether or not that's true depends on the use case; the really relevant sense of homogenous or heterogenous that distinguishes the idiomatic use of tuples vs. lists is contextual, and is more about the interfaces that the consuming code expects the members to provide than the explicit classes per se. There's nothing unidiomatic in Python about using a list for a series of items of different explicit classes that are going to have the same operations (supported by a common interface they all share) performed on them.