why no 'length' method in sequences ?

Geoff Gerrietts geoff at gerrietts.net
Fri Apr 19 15:28:47 EDT 2002


Quoting Just van Rossum (just at xs4all.nl):
> I appreciate and agree with what you write, and I like how Python does 
> things, too, BUT I can totally see why people find it strange that to 
> get the length of an object you write
> 
>     len(o)
> 
> and to get (eg.) the keys from a dictionary you do
> 
>     o.keys()

I'm interested in this thread only because of the special case of the
len() function -- I still find myself, even after a couple years of
using it, occassionally writing object.len() instead of len(object).

I think it's because in my head, most of the functions in Python
operate /on/ objects, while I think of a length as more of an
attribute /of/ an object.

Maybe that distinction is artificial, or maybe it's less about Python
and more about how I think about functions vs. methods. It's certainly
a more OO-centric way of thinking about the two.

I don't know that this situation calls for correction, or whether it
calls for education, or whether it's just a strange corner-case that
might bear consideration when thinking about the broader language
design issues.

It's just interesting to me, that others are expressing a similar
sentiment.

Thanks,
--G.

-- 
Geoff Gerrietts             "There is no fate that cannot be 
<geoff at gerrietts net>     surmounted by scorn." --Albert Camus





More information about the Python-list mailing list