When teaching students Python lists (which are more like arrays, not linked-lists) I’d like to use metaphor of list being a collection of boxes put in row.
But this doesn’t work well:
- indexes are important to be numbers, but in my example indexes should actually be counted, and it is not obvious that "counted" and "index" are same. At least, from performance PoV indexes are not "counted"
- and I can’t name boxes with increasing numbers, as this is plain wrong, indexes are not names of boxes, they are property of list itself. For example, list slice or splice should change names of boxes, which isn’t realistic
- the boxes metaphor fails for list of lists
A slightly better metaphor for list of integers is:
- list is a train with wagons of same length
- and indexes are special signs on railway platform
- the train stays near platform in such way, that the connection between train and first wagon is next to sign with number "0", index 0
- other signs on platform stays near other connections in an increasing order
- the train head and railway platform together are a list, the wagons are elements of a list
- any slice or splice of train wagons is done with train head staying where it stays and extending/squashing all remaining wagons to be connected.
This is slightly more correct, but fails for list of lists (or list of objects). Are there better metaphors?