Collections of non-arbitrary objects ?
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Thu Jun 28 00:36:25 EDT 2007
walterbyrd a écrit :
> On Jun 26, 8:23 am, Bruno Desthuilliers <bruno.
> 42.desthuilli... at wtf.websiteburo.oops.com> wrote:
>
>>walterbyrda écrit :
>>
>>
>>>>You do program carefully, don't you ?-)
>>
>>>I try. But things like typos are a normal part a life.
>>
>>So are they in any language. I fail to see much difference here.
>>
>
>
> For example: if I mis-type a variable name in C, the program will
> probably not even compile.
It sometimes happens - but chances are low, for sure.
> Whereas, with Python, the program will
> probably run, but may give unexpected results.
>
Yes, true. Well, in some cases. In one case, to be true: the use of the
'=' operator. IIRC, any other use of an undefined symbol will raise an
exception. But this has to do with how symbols are defined in Python
(ie: the fact that binding => definition), and has nothing to do with
static (compile-time) type checking.
>
>>>Guido
>>>must think python has a lot of room for improvement since he's
>>>completely throwing out backward compatibility with python 3000.
>>
>>Not "completely throwing out". Just allowing *some* major breakages -
>>the kind you usually get with each major release of other languages, but
>>that Python managed to avoid as much as possible so far.
>
>
> I don't know, but here is a direct quote from Guido's blog: "Python
> 3.0 will break backwards compatibility. Totally."
>
> http://www.artima.com/weblogs/viewpost.jsp?thread=208549
Please take it with a grain of the salt. This is mostly about getting
rid of long-time deprecated features.
>
>>>It seems to me that tuple are essentially immutable lists.
>>
>>They are not (even if you can use them that way too). FWIW and IIRC,
>>this is a FAQ.
>
> A few posters here have stated that tuples are not just immutable but
> when I compare lists, to tuples, I notice that both are ordered
> collections of arbitrary objects, with the primary difference being
> that list are mutable, and tuples are not.
This is of course technically true. And you forgot to compare to sets,
while we're at it. But the answer to your questions about tuples is not
technical - it's about use case.
> It seems to me that if a
> list were immutable, it would be a tuple. That is the one big
> difference.
>
> Tuples have been compared to records/structures in other languages.
> But, in general, I can not use a for loop to loop through the fields
> in a record,
For which definition of "in general" ? I can do this with at least
Python, PHP, Javascript, Ruby, and probably Java (IIRC).
> and I can not sort those fields either.
Did you try to sort a tuple ?
>>> (1, "aaa").sort()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'tuple' object has no attribute 'sort'
More information about the Python-list
mailing list