Mix-In Class Methods At Run-Time

digitalorganics at gmail.com digitalorganics at gmail.com
Mon Jun 26 19:45:04 CEST 2006


Bruno Desthuilliers wrote:
> digitalorganics at gmail.com wrote:
> > Bruno Desthuilliers wrote:
> >
> >>digitalorganics at gmail.com wrote:
> (snip)
>
> >>>and 2) what's the reason to use newstyle classes
> >>>versus the old?
> >>
> >>All this is explained on python.org (there's a menu entry for this in
> >>the documentation menu). AFAICT, newstyle classes can do whatever
> >>oldstyle classes did, *and much more* (descriptors and usable
> >>metaclasses) - and they are somewhat faster too. So - compatibility with
> >>older Python versions (< 2.2 IIRC) set aside -, there's just no reason
> >>to use oldstyle classes.
> >>
> >>
> >>> In order to create the dynamic class "NewClass" in the
> >>>code above I called type() but that requires at least one new style
> >>>class as a base. Thus, I had to have at least one of my animals inherit
> >>>from "object" and this seemed a nuisance since
> >>
> >>OMG, eight more keystrokes - talk about a nuisance...
> >
> >
> > Like, Oh My God! *claps hand to mouth*  lol   You humor me. Yes, eight
> > more keystrokes. I follow the general rule of, if I'm going to put in
> > extra effort,
>
> OMG, eight more keystrokes - talk about extra effort !-)

As I said, its not the effort, its the personal need to know why the
effort, however small, is being put in.

>
> > I'd like to know why.
>
> The only reason for *not* doing it would be compat issues with pre 2.2.x
> versions.
>
> > So you see, it's not so much an
> > adversion to the eight keystrokes (multiplied by however many classes I
> > have mind you),
>
> Strange enough, I do write my share of Python code, and don't even
> notice typing the EightKeystrokes.
>
> > but to not knowing why I should use them.
>
> Because they are kind of the standard Python object model since 2.2.x ?-)

What kind of answer is that? What does that actually mean to me? I'm
talking practical reasons here....

>
> Did you at least take time to read the doc on newstyle classes on
> python.org ?
>
> FWIW, with 2.5, even exceptions are now newstyle classes. No more
> oldstyle classes in the builtins. And AFAICT, no more oldstyle classes
> in the standard lib neither. Does that ring a bell ?

Yes yes, but I've been able to use all that without declaring a single
new-style class. So my question was, what penalty do I actually pay...

>
> > If I don't
> > care for descriptors or metaclasses,
>
> You *do* care for descriptors. Without descriptors, no properties, no
> classmethods, no staticmethods... What a desolation :(
>
> More seriously, given what you're into actually, not caring about what
> one can do with newstyle classes seems really strange to me - like
> digging a swimming-pool with a pick and a shovel when you have an
> excavator... (disclaimer : google translation, not sure it makes sens in
> english...)

You have it backwards. Of course I care what can be done with new-style
classes. That was precisely the basis for my original question. I
wanted to know what those eight keystrokes * #ofclasses gets me, and if
its necessary versus just a key to unlock features that I may or may
not need.




More information about the Python-list mailing list