What is not objects in Python?

Carl Banks pavlovevidence at gmail.com
Mon Sep 29 08:34:14 CEST 2008

On Sep 29, 1:44 am, George Sakkis <george.sak... at gmail.com> wrote:
> On Sep 29, 12:08 am, Terry Reedy <tjre... at udel.edu> wrote:
> > George Sakkis wrote:
> > > On Sep 28, 2:29 pm, process <circularf... at gmail.com> wrote:
> > >> I have heard some criticism about Python, that it is not fully object-
> > >> oriented.
> > > That's not a bug, it's a feature ;-)
> > >> Why isn't len implemented as a str.len and list.len method instead of
> > >> a len(list) function?
> > > As Terry Reedy wrote, partly history and partly practicality. There's
> > > no philosophical reason why we write "len(x)" (generic builtin),
> > > "x.append(1)" (method) or "del x[i]" (statement). The latter in
> > > particular is IMHO a design wart; there's no reason for not writing it
> > > as "x.delete(i)".
> > As a general rule and matter of practice, methods that apply to all or
> > most classes (or all number classes) have built-in functions that call
> > the corresponding special method (or C-level slot).
> It would be easier to justify this rule if it was more clear-cut, and
> specifically if it was applied only to methods that are available to
> *all* classes (such as type() and getattr()) rather than the ill-
> defined "most classes".

That wasn't your original claim, though.  You claimed there was no
philosophical reason, then Terry gave you one, then you said, well
there's no clear cut reason.  Unless you define "philosophical" as
"clear cut" (a definition I'm not sure many would agree with).

Anyway, you are right to claim there's no clear cut distinction, just
as there's never any clear cut distinction over whether something
should be an operator or not. Addition is only available to the ill-
defined "most classes", yet not only is it not a method, it has its
own syntax.  There's no clear cut distinction there, it's just a
design decision.  Likewise, making len() into a function is just a
design decision, that len is a common enough operation that it need
elevated status.  It's really nothing more.  Python wouldn't suffer
much regardless if len is a method, a built-in function, or an
operator with its own syntax.

Carl Banks

More information about the Python-list mailing list