Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > why are people still using classic classes?

Reply
Thread Tools

why are people still using classic classes?

 
 
Aahz
Guest
Posts: n/a
 
      01-13-2005
In article <(E-Mail Removed)>,
Peter Hansen <(E-Mail Removed)> 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 ((E-Mail Removed)) <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing." --Alan Perlis
 
Reply With Quote
 
 
 
 
Simon Wittber
Guest
Posts: n/a
 
      01-13-2005
> 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.
 
Reply With Quote
 
 
 
 
Aahz
Guest
Posts: n/a
 
      01-13-2005
In article <(E-Mail Removed)>,
Simon Wittber <(E-Mail Removed)> 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 ((E-Mail Removed)) <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing." --Alan Perlis
 
Reply With Quote
 
Michael Hobbs
Guest
Posts: n/a
 
      01-13-2005
Simon Wittber <(E-Mail Removed)> 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




 
Reply With Quote
 
Jarek Zgoda
Guest
Posts: n/a
 
      01-13-2005
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/
 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      01-14-2005
Peter Hansen wrote:

> Paul Rubin wrote:
>
>> Simon Wittber <(E-Mail Removed)> 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
 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      01-14-2005
Michael Hobbs wrote:

> Simon Wittber <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do people still use C instead of C++ ? Lawand C++ 42 05-21-2011 03:44 AM
People still using Tkinter? Kenneth McDonald Python 11 05-10-2008 04:02 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Why do people still insist that the holocaust didn't occur? Fred A. Miller Digital Photography 11 02-26-2004 12:49 AM



Advertisments