why are people still using classic classes?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Wittber

    #1

    why are people still using classic classes?

    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?

    Sw.
  • Roy Smith

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

    Simon Wittber <simonwittber@g mail.com> wrote:[color=blue]
    > Is there a legitimate use for classic classes that I am not aware of?[/color]

    Is there a reason NOT to use them? If a classic class works fine, what
    incentive is there to switch to new style classes? I realize it's not
    much effort to put "(object)" after your class name, but I'm lazy and
    don't bother. I don't see how I've been hurt by that.

    Obviously, if there was some feature of new style classes I wanted to
    use, it would be a different story.

    Comment

    • Simon Wittber

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

      > Is there a reason NOT to use them? If a classic class works fine, what[color=blue]
      > incentive is there to switch to new style classes?[/color]

      Perhaps classic classes will eventually disappear? It seems strange
      (and is difficult to explain to my peers) that a language offers two
      different ways to define a standard class.

      Sw.

      Comment

      • John Roth

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


        "Simon Wittber" <simonwittber@g mail.com> wrote in message
        news:mailman.60 5.1105586518.22 381.python-list@python.org ...[color=blue]
        > 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]

        Part of it is simply that it's a bit easier: you don't have to
        inherit from object.

        AFAIK, there's no project to migrate the standard library, and I'm
        not at all sure that would be a good idea since existing programs
        that asssume classic class behavior would be affected when
        classes they inherited from suddenly changed.

        Classic classes will go away sometime in the future, currently
        planned for the semi-mythical 3.0 release.

        John Roth[color=blue]
        >
        > Sw.[/color]

        Comment

        • Paul Rubin

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

          Simon Wittber <simonwittber@g mail.com> writes:[color=blue]
          > Is there a legitimate use for classic classes that I am not aware of?[/color]

          Yes, new-style classes don't work in older Python installations. Some
          Python users prefer not to be on such a frequent upgrade treadmill, so
          they continue to use old versions. Therefore, anyone writing Python
          code for wide distribution should avoid using new-style classes (and
          other new Python features) unless they have a good reason.

          Comment

          • Paul Rubin

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

            Simon Wittber <simonwittber@g mail.com> writes:[color=blue][color=green]
            > > Is there a reason NOT to use them? If a classic class works fine, what
            > > incentive is there to switch to new style classes?[/color]
            >
            > 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.

            It would be nice if a __future__ directive were added right now (if
            it's not there already) that processes all class definitions as
            new-style. Otherwise there's no easy way to test for compatibility.

            Comment

            • Aahz

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

              In article <mailman.605.11 05586518.22381. python-list@python.org >,
              Simon Wittber <simonwittber@g mail.com> wrote:[color=blue]
              >
              >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]

              Exceptions, in addition to the other excellent reasons you've been
              provided.
              --
              Aahz (aahz@pythoncra ft.com) <*> http://www.pythoncraft.com/

              "19. A language that doesn't affect the way you think about programming,
              is not worth knowing." --Alan Perlis

              Comment

              • Bengt Richter

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

                On 12 Jan 2005 20:06:39 -0800, Paul Rubin <http://phr.cx@NOSPAM.i nvalid> wrote:
                [color=blue]
                >Simon Wittber <simonwittber@g mail.com> writes:[color=green][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?[/color]
                >>
                >> 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.
                >
                >It would be nice if a __future__ directive were added right now (if
                >it's not there already) that processes all class definitions as
                >new-style. Otherwise there's no easy way to test for compatibility.[/color]

                UIAM, it's not so bad:
                [color=blue][color=green][color=darkred]
                >>> class C: pass[/color][/color][/color]
                ...[color=blue][color=green][color=darkred]
                >>> type(C)[/color][/color][/color]
                <type 'classobj'>[color=blue][color=green][color=darkred]
                >>> class D(object): pass[/color][/color][/color]
                ...[color=blue][color=green][color=darkred]
                >>> type(D)[/color][/color][/color]
                <type 'type'>[color=blue][color=green][color=darkred]
                >>> __metaclass__ = type
                >>> class E: pass[/color][/color][/color]
                ...[color=blue][color=green][color=darkred]
                >>> type(E)[/color][/color][/color]
                <type 'type'>

                So I guess you can put __metaclass__ = type where you would have done the __future__ thing.

                If you want to do a special metaclass thing (even using a proper class ;-),
                you can override the global __metaclass__
                [color=blue][color=green][color=darkred]
                >>> def MC(*a): print a; return type(*a)[/color][/color][/color]
                ...[color=blue][color=green][color=darkred]
                >>> class F:[/color][/color][/color]
                ... __metaclass__ = MC
                ... pass
                ...
                ('F', (), {'__module__': '__main__', '__metaclass__' : <function MC at 0x02EE8D4C>})

                Regards,
                Bengt Richter

                Comment

                • Tim Roberts

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

                  Simon Wittber <simonwittber@g mail.com> wrote:
                  [color=blue]
                  >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]

                  Probably because there is still no compelling reason to break the old
                  habits and type those 6 extra characters.

                  Once a person has a case where the new classes make a difference, I suspect
                  they catch the new habit and never look back. I haven't crossed that
                  threshhold yet.
                  --
                  - Tim Roberts, timr@probo.com
                  Providenza & Boekelheide, Inc.

                  Comment

                  • Peter Hansen

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

                    Paul Rubin wrote:[color=blue]
                    > Simon Wittber <simonwittber@g mail.com> writes:
                    >[color=green][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?[/color]
                    >>
                    >>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=blue][color=green][color=darkred]
                    >>> class Classic:[/color][/color][/color]
                    .... def __init__(self):
                    .... super(Classic, self).__init__( )
                    ....[color=blue][color=green][color=darkred]
                    >>> c = Classic()[/color][/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?

                    -Peter

                    Comment

                    • Aahz

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

                      In article <R_udnQYX0Nxw53 vcRVn-hw@powergate.ca >,
                      Peter Hansen <peter@engcorp. com> wrote:[color=blue]
                      >
                      >Unfortunatel y, 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]

                      Maybe. If you follow the python-dev thread about "super() considered
                      harmful", you'll learn that Guido believes super() should only be used
                      with class hierarchies explicitly designed for the purpose. Given that,
                      you'd have to do a lot of other changes to support super() and it's less
                      outrageous.
                      --
                      Aahz (aahz@pythoncra ft.com) <*> http://www.pythoncraft.com/

                      "19. A language that doesn't affect the way you think about programming,
                      is not worth knowing." --Alan Perlis

                      Comment

                      • Simon Wittber

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

                        > Unfortunately, if we should follow the recent advice about[color=blue]
                        > 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]

                        'import this' also provides some good advice:

                        "There should be one-- and preferably only one --obvious way to do it."

                        It seems to me that python is not as simple/clean as it once was. It
                        has grown warts, for the sake of backwards compatibility. :(

                        Sw.

                        Comment

                        • Aahz

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

                          In article <mailman.638.11 05624714.22381. python-list@python.org >,
                          Simon Wittber <simonwittber@g mail.com> wrote:[color=blue]
                          >
                          >'import this' also provides some good advice:
                          >
                          >"There should be one-- and preferably only one --obvious way to do it."
                          >
                          >It seems to me that python is not as simple/clean as it once was. It
                          >has grown warts, for the sake of backwards compatibility. :([/color]

                          That's progress. One of the primary goals for Python 3.0 is to make a
                          fresh start by removing a lot of the backwards compatibility.
                          --
                          Aahz (aahz@pythoncra ft.com) <*> http://www.pythoncraft.com/

                          "19. A language that doesn't affect the way you think about programming,
                          is not worth knowing." --Alan Perlis

                          Comment

                          • Michael Hobbs

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

                            Simon Wittber <simonwittber@g mail.com> wrote:[color=blue]
                            > 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:


                            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.

                            Regards,
                            - Mike




                            Comment

                            • Jarek Zgoda

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

                              Paul Rubin wrote:
                              [color=blue][color=green][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?[/color]
                              >>
                              >>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]

                              Ideally, I'd like to have them working like in Delphi, where it doesn't
                              matter if you declare it as TSomeClass(TObj ect) or simply TSomeClass, it
                              is assumed that class is inherited from TObject if no other class is
                              specified.

                              --
                              Jarek Zgoda
                              http://jpa.berlios.de/ | http://www.zgodowie.org/

                              Comment

                              Working...