why are people still using classic classes?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Holden

    #16
    Re: why are people still using classic classes?

    Peter Hansen wrote:
    [color=blue]
    > Paul Rubin wrote:
    >[color=green]
    >> Simon Wittber <simonwittber@g mail.com> writes:
    >>[color=darkred]
    >>>> Is there a reason NOT to use them? If a classic class works fine, what
    >>>> incentive is there to switch to new style classes?
    >>>
    >>>
    >>> Perhaps classic classes will eventually disappear?[/color]
    >>
    >>
    >> It just means that the formerly "classic" syntax will define a
    >> new-style class. Try to write code that works either way.[/color]
    >
    >
    > Unfortunately, if we should follow the recent advice about
    > always using "super()" in the __init__ method, it's hard
    > to do what you suggest (though it sounds like good advice)
    > without resorting to extreme ugliness:
    >[color=green][color=darkred]
    > >>> class Classic:[/color][/color]
    > .... def __init__(self):
    > .... super(Classic, self).__init__( )
    > ....[color=green][color=darkred]
    > >>> c = Classic()[/color][/color]
    > Traceback (most recent call last):
    > File "<stdin>", line 1, in ?
    > File "<stdin>", line 3, in __init__
    > TypeError: super() argument 1 must be type, not classobj
    >
    > Could classic classes ever be removed without us having manually
    > to fix all __init__ calls to the superclass?
    >[/color]
    That's not really an issue unless there's a diamond-shaped inheritance
    graph and linearisation of the the super classes is required to ensure
    that things stay sane. Remembering that the MO for classic classes and
    types are rather different, how many cases do you think it will matter?

    regards
    Steve
    --
    Steve Holden http://www.holdenweb.com/
    Python Web Programming http://pydish.holdenweb.com/
    Holden Web LLC +1 703 861 4237 +1 800 494 3119

    Comment

    • Steve Holden

      #17
      Re: why are people still using classic classes?

      Michael Hobbs wrote:
      [color=blue]
      > Simon Wittber <simonwittber@g mail.com> wrote:
      >[color=green]
      >>I've noticed that a few ASPN cookbook recipes, which are recent
      >>additions, use classic classes.
      >>
      >>I've also noticed classic classes are used in many places in the
      >>standard library.
      >>
      >>I've been using new-style classes since Python 2.2, and am suprised
      >>people are still using the classic classes.
      >>
      >>Is there a legitimate use for classic classes that I am not aware of?
      >>Is there a project to specifically migrate standard library classes to
      >>new-style classes?[/color]
      >
      >
      > I'm guessing that the biggest contributor to the continued prevalence
      > of classic classes is the official Python Tutorial:
      > http://docs.python.org/tut/node11.ht...00000000000000
      >
      > I came into Python around the 2.2 timeframe and used the tutorial as
      > my starting point. I had often read people referring to "classic
      > classes" but assumed that it was some old pre-2.2 thing that I need
      > not worry about. For the longest time, I had assumed that I was using
      > new style classes because I created them exactly as prescribed in the
      > 2.2 tutorial (which still hasn't changed for 2.3 or 2.4).
      >
      > Now, classic classes are my habit and I see no compelling reason to
      > put in the effort to change my habits.
      >[/color]

      Since the only effort is the addition of

      __meta class__ = type

      at the head of your modules you could probably automate this without
      breaking too much code.

      regards
      Steve
      --
      Steve Holden http://www.holdenweb.com/
      Python Web Programming http://pydish.holdenweb.com/
      Holden Web LLC +1 703 861 4237 +1 800 494 3119

      Comment

      Working...