Semantics of collection types (was: Late-binding of function defaults (was Re: What is a function parameter =[] for?))

Ben Finney ben+python at benfinney.id.au
Thu Nov 26 00:04:39 EST 2015


Ian Kelly <ian.g.kelly at gmail.com> writes:

> On Wed, Nov 25, 2015 at 5:52 PM, Random832 <random832 at fastmail.com> wrote:
> > On 2015-11-25, Ben Finney <ben+python at benfinney.id.au> wrote:
> >> That is, the ‘2’ in ‘cartesian_point = (2, 3)’ means something
> >> different than in ‘cartesian_point = (3, 2)’.
> >>
> >> Whereas the ‘2’ in ‘test_scores = [2, 3]’ means exactly the same as
> >> in ‘test_scores = [3, 2]’.
> >>
> >> If each position in the sequence gives the value there a different
> >> menaning, use a tuple; if not, use a list.
> >
> > I don't think that's really right.

I was expanding on (by replying to) earlier advice about expressing
semantics in our choice of data types.

> > The difference between a tuple and a list is that one is mutable
> > and the other is not.

That is a difference enforced in the behaviour of the types, yes.

I didn't talk about behaviour, but about meaning. I'm saying that the
behavioural difference conveniently lines up with a semantic difference,
even to the point of the meaning of “tuple” that pre-dates Python.

> I think that Ben was actually trying to make a distinction between
> heterogeneity and homogeneity of the contents, not a distinction of
> whether the collection was ordered or not.

That's right, thank you.

-- 
 \       “Nothing exists except atoms and empty space; everything else |
  `\                    is opinion.” —Democritus, c. 460 BCE – 370 BCE |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list