News for hackers. Stuff that matters.
Re:Python Lists vs. Tuples by markrages on Friday August 19, 2016 @10:38PM (#12324874)
> it would be nonsensical to write code which iterated over a list or tuple containing heterogeneous data.

There are Python functions that take any type like repr() or id()

Re:Python Lists vs. Tuples by colanderman on Friday August 19, 2016 @11:28PM (#12325030)
See my other comment; it does make sense to have a list of objects which share some interface. In the case you suggest, it is a very trivial and not-very-useful interface, but an interface nonetheless. You can do this with objects even in strictly-typed languages like OCaml or Mercury; code which iterates over the list is simply restricted to use only those methods which all elements have in common.

Of course in languages which don't support a universal "object" type (say OCaml or C) you cannot do this -- numbers and strings have no interface in common. Those languages take advantage of this by not storing type information in collections (e.g. OCaml's float arrays, or any array in C), thus resulting in more compact memory footprints. If they instead allowed heterogeneous collections, the memory footprint of such collections would double.

Re:Python Lists vs. Tuples by aangjie on Friday August 19, 2016 @11:33PM (#12325046)
> There are Python functions that take any type like repr() or id()

Umm.. I haven't had to use any of them on a list(or for that matter on an object) for code.. (except when I'm curious and poking at python internals) May be I'm stuck in a web application role? Is it actually useful to say call repr() on a list of objects? May be call id to see if there's references to same object twice? I'm finding it hard to imagine cases where it would be needed to implement a feature, that wouldn't be better served by alternate methods.

Re:Python Lists vs. Tuples by davrosthedalek on Friday August 19, 2016 @11:33PM (#12325048)
One could argue that for those, the semantic differences between the types are dropped. In OO lingo, they look at the properties of the common base class.