Python-list digest, Vol 1 #10572 - 14 msgs

James J. Besemer jb at cascade-sys.com
Fri Apr 19 23:38:33 EDT 2002


>
> Quoting Just van Rossum (just at xs4all.nl):
> ? 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()
>
> To which Geoff Gerrietts ?geoff at gerrietts.net> added:
> 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.

It seems that Python started out (as a Lisp derivitave) with much less of an OO emphasis.  I expect len(o) has precedent dating back to the original language.

However, over time Python has increasingly placed much greater emphasis on Objects.  Furthermore, OO programming generally has evolved from an experimental following to mainstream.  In this process, the universe has changed.  For one to say he expects o.len() to work is eminently reasonable and it's increasingly a wart on the language
that you have to revert to an alternative notation.

After all, when it is increasingly common for us to use OO notation for things like

    "a b c".split()

it's increasingly grating for "a b c".len() to be an ERROR.

I think o.len() should be recognized as a synonym for len(o).  Certainly the language has sustained a number of more dramatic changes in recent years.

Regards

--jb

--
James J. Besemer  503-280-0838 voice
http://cascade-sys.com  503-280-0375 fax
mailto:jb at cascade-sys.com







More information about the Python-list mailing list