Python's theoretically missing core data type
In theory in Python, tuples are for heterogeneous data and lists are for homogeneous data. Except, well, tuples and lists have 'side effects': tuples are read-only and lists are not. Which means that if you take the restriction on lists seriously, you do not have a core data type for ordered writeable heterogeneous data (and maybe also one for read-only homogeneous data).
(While this is a theory that's probably more honored in the breach than in practice, I think that it does have some consequences, especially for determining what things go into the standard library.)
All of which gets us to the issue of whether one should hijack lists for the situation where you need ordered writeable heterogeneous data. On the one hand, if lists are for heterogeneous data and this is their most important attribute, then people who hijack them are doing it wrong; not only are they writing un-Pythonic code, but they are probably not going to get the support they'd like from the standard library.
On the other hand, I think that ordered writeable heterogeneous data is a common enough pattern that there should be a core type that supports it; there are a fair number of situations with ordered, modifiable fields. (If nothing else, I note that any serialization format imposes a field order on otherwise unordered structures.)
In theory you could add another core type to Python for this. In practice I think it would be the wrong answer; there would be little functional difference between lists and the new data type, so you'd be adding it merely for intellectual purity. This is unlikely to be attractive to either language designers or Python programmers.
All of which leads me to the opinion that the list purists should yield a bit and accept that for the overall good of Python, lists can be legitimately used for heterogeneous data as well as homogeneous data. Carrying this through to what gets added to the standard library would be nice, too.
Comments on this page:Written on 08 March 2009.