Re: preferring  or () in list of error codes?
Gabriel Genellina <gagsl-py2 <at> yahoo.com.ar>
2009-06-11 14:47:58 GMT
En Tue, 09 Jun 2009 05:02:33 -0300, Steven D'Aprano
<steven <at> remove.this.cybersource.com.au> escribió:
> [...] As tuples are defined in Python, they quack like immutable lists,
> walk like immutable lists, and they swim like immutable lists. Why
> shouldn't we treat them as immutable lists?
> Phillip Eby states that "Lists are intended to be homogeneous sequences,
> while tuples are heterogeneous data structures." (Notice the subtle shift
> there: lists are "intended", while tuples "are". But in fact, there's
> nothing to stop you from putting homogeneous data into a tuple, so Eby is
> wrong to say that tuples *are* heterogeneous.)
> Perhaps Eby intends lists to be homogeneous, perhaps Guido does too, but
> this is Python, where we vigorously defend the right to shoot ourselves
> in the foot. We strongly discourage class creators from trying to enforce
> their intentions by using private attributes, and even when we allow such
> a thing, the nature of Python is that nothing is truly private. Why
> should homogeneity and heterogeneity of lists and tuples be sacrosanct?
> Nothing stops me from putting hetereogeneous data into a list, or
> homogeneous data into a tuple, and there doesn't appear to be any ill-
> effects from doing so. Why give lose sleep over the alleged lack of
Yes - but in the past the distinction was very much stronger. I think that
tuples didn't have *any* method until Python 2.0 -- so, even if someone
could consider a tuple a "read-only list", the illusion disappeared as
soon as she tried to write anything more complex that a[i]. Maybe tuples
could quack like immutable lists, but they could not swim nor walk...