473,241 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

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.
Jul 18 '05 #1
16 2022
Simon Wittber <si**********@gmail.com> wrote:
Is there a legitimate use for classic classes that I am not aware of?


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.
Jul 18 '05 #2
> 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? It seems strange
(and is difficult to explain to my peers) that a language offers two
different ways to define a standard class.

Sw.
Jul 18 '05 #3

"Simon Wittber" <si**********@gmail.com> wrote in message
news:ma**************************************@pyth on.org...
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?
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
Sw.


Jul 18 '05 #4
Simon Wittber <si**********@gmail.com> writes:
Is there a legitimate use for classic classes that I am not aware of?


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.
Jul 18 '05 #5
Simon Wittber <si**********@gmail.com> writes:
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?


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.
Jul 18 '05 #6
In article <ma**************************************@python.o rg>,
Simon Wittber <si**********@gmail.com> wrote:

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?


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

"19. A language that doesn't affect the way you think about programming,
is not worth knowing." --Alan Perlis
Jul 18 '05 #7
On 12 Jan 2005 20:06:39 -0800, Paul Rubin <http://ph****@NOSPAM.invalid> wrote:
Simon Wittber <si**********@gmail.com> writes:
> 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?


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.


UIAM, it's not so bad:
class C: pass ... type(C) <type 'classobj'> class D(object): pass ... type(D) <type 'type'> __metaclass__ = type
class E: pass ... type(E) <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__
def MC(*a): print a; return type(*a) ... class F:

... __metaclass__ = MC
... pass
...
('F', (), {'__module__': '__main__', '__metaclass__': <function MC at 0x02EE8D4C>})

Regards,
Bengt Richter
Jul 18 '05 #8
Simon Wittber <si**********@gmail.com> wrote:
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?


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, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #9
Paul Rubin wrote:
Simon Wittber <si**********@gmail.com> writes:
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?


It just means that the formerly "classic" syntax will define a
new-style class. Try to write code that works either way.


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:
class Classic: .... def __init__(self):
.... super(Classic, self).__init__()
.... c = Classic()

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
Jul 18 '05 #10
In article <R_********************@powergate.ca>,
Peter Hansen <pe***@engcorp.com> wrote:

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:
class Classic:... def __init__(self):
... super(Classic, self).__init__()
... c = Classic()

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?


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 (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing." --Alan Perlis
Jul 18 '05 #11
> 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:


'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.
Jul 18 '05 #12
In article <ma**************************************@python.o rg>,
Simon Wittber <si**********@gmail.com> wrote:

'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. :(


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 (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing." --Alan Perlis
Jul 18 '05 #13
Simon Wittber <si**********@gmail.com> wrote:
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?


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.

Regards,
- Mike


Jul 18 '05 #14
Paul Rubin wrote:
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?


It just means that the formerly "classic" syntax will define a
new-style class. Try to write code that works either way.


Ideally, I'd like to have them working like in Delphi, where it doesn't
matter if you declare it as TSomeClass(TObject) 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/
Jul 18 '05 #15
Peter Hansen wrote:
Paul Rubin wrote:
Simon Wittber <si**********@gmail.com> writes:
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?

It just means that the formerly "classic" syntax will define a
new-style class. Try to write code that works either way.

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:
>>> class Classic: .... def __init__(self):
.... super(Classic, self).__init__()
.... >>> c = Classic()

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?

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
Jul 18 '05 #16
Michael Hobbs wrote:
Simon Wittber <si**********@gmail.com> wrote:
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?

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.


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
Jul 18 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Chris S. | last post by:
I'm generating the source of an object from a list of objects. Therefore I need to determine if the object is a class definition (i.e. 'def something(whatever):') or a class instance (i.e....
3
by: ShepardBerry | last post by:
I've been working in .NET for some time now and I don't remember specifically how asp classes are cleaned up in classic asp. I've been put on a Classic ASP project(ugh) and we're having some...
14
by: Tony Johansson | last post by:
Hello Experts! Assume I have a class called SphereClass as the base class and a class called BallClass that is derived from the SphereClass. The copy constructor initialize the left hand object...
5
by: venk | last post by:
Hi, can some one properly explain the differences between class types and classic classes? ... Still face problems in identifying what is what.
3
by: Brian Birtle | last post by:
**** A CHALLENGE TO THE GURUS - refute the statement "It's impossible to build a file upload progress meter using ASP.NET" **** First person to prove me wrong gets "All Time .NET Programming GOD"...
3
by: nevets2001uk | last post by:
Hi. I've just started my second ASP.NET (VB) app and I'm using codebehind this time. I'm not using visual studio but am instead coding it all in notepad (HTML, ASP.NET and CSS) I'm trying to...
1
by: ankit | last post by:
Hello, Please put some light on, What are new style classes and classic style classes in python. The basic differences in them. And How can I decide to choose one.
1
by: Kay Schluehr | last post by:
Just reasoning about conversion of classic to new style classes ( keeping deprecation of ClCl in Py3K in mind ) I wonder if there is a metaclass that can be used to express the semantics of ClCl in...
4
by: Quek | last post by:
Hi all, I'm really new to Python and I've been reading up some texts on older versions of Python (2.2 to be specific). The text briefly mentioned new style and classic classes. I'd really...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.