473,782 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

New-style classes questions

I'm confused by the concepts of old-style vs new-style classes, I've read
most of the documents I found about this but it doesn't "click". Probably
because I wasn't around before 2.2.

Anyway, the reason for new style classes are to make the whole type/object
thing work better together. There are a number of new features etc.

I think my problem is when new-style classes are used, at first I thought
that all classes become new-style classes when I was using 2.4, but if I
understand things correctly I need to subclass an existing class (assuming
that this class does the same) for it to become a new-style class.

Have I understood this correctly?

If I have, then I've got the following question:
=============== =============== =============== ===
Then I could write:

class Foo( Object )

to make a new-style class, and

class FooA

to make an old-style class.
What is the reason for allowing both styles? (backwards compatibility?? )

When I make my own classes should they always be new-style objects or are
there reasons for using old-style object?
=============== =============== =============== ===
Sep 25 '05 #1
3 1281
> What is the reason for allowing both styles? (backwards compatibility?? )

yes.

When I make my own classes should they always be new-style objects or are
there reasons for using old-style object?


No, use new style if you can - except from the rare cases where above
mentioned backwards compatibilty is needed. E.g. exceptions have to be
old-style, and for example omniorb needs old-style classes for corba
implementations .

Diez
Sep 25 '05 #2
Diez B. Roggisch wrote:
What is the reason for allowing both styles? (backwards compatibility?? )


yes.


Note that there is another way to create new-style classes:

__metaclass__ = type

before the first class definition:
class Foo: pass .... type(Foo) <type 'classobj'> __metaclass__ = type
class Bar: pass .... type(Bar)

<type 'type'>

I like this. However, perhaps other people reading my source code won't
like it, because when they see 'class Foo:', they might expect an
old-style class. But it's so much better to type and to read, that I
prefer this.

Does the Python style guide have any severe penalty for using this?

regards,
Gerrit.

--
Temperature in Luleå, Norrbotten, Sweden:
| Current temperature 05-09-25 15:19:47 11.0 degrees Celsius ( 51.9F) |
--
Det finns inte dåligt väder, bara dåliga kläder.
Sep 25 '05 #3
On Sun, 25 Sep 2005 15:24:29 +0200, Gerrit Holl wrote
(in article <ma************ *************** *********@pytho n.org>):
I like this. However, perhaps other people reading my source code won't
like it, because when they see 'class Foo:', they might expect an
old-style class. But it's so much better to type and to read, that I
prefer this.
I personally would find this more difficult to read but it's a matter of
taste I suppose.
Det finns inte dåligt väder, bara dåliga kläder.


Så sant som det var sagt
jem

Sep 25 '05 #4

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

Similar topics

4
1828
by: Madestro | last post by:
Hi guys, I am making a small program to retrieve e-mails from POP accounts. I got all the e-mail parsing stuff figured out, but I cannot seem to come up with a way to find out which e-mails are NEW so I don't have to retrieve them all. If you have experience with this kind of thing, you know that the server creates unique IDs for all the messages, but this IDs are not guaranteed to be unique, since they can be reused once a message is...
3
9417
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. I am presenting below a summary of what I have gathered. I would appreciate if someone could point out to something that is specific to Borland C++ and is not supported by the ANSI standard. I am also concerned that some of the information may be outdated...
20
1845
by: Razvan | last post by:
Hi ! Is there any difference between new X and new X() ?! Regards, Razvan
11
912
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have nice and working allocation deallocation routines. However, I don't want to loose the nice extras of new operator, like - constructor calling, typecasting the result, keeping the array size, etc. For another bunch of reasons, outside this scope I...
5
2402
by: kUfa.scoopex | last post by:
Hi there! I have a small problem, and i really dont see any convenient way to fix it. Basically, i'd like to overload global new operators, into something like this: void *operator new( size_t size ); void *operator new( size_t size, AllocationType allocType ); void *operator new( size_t size, MemoryHandler* memHandler ); void *operator new( size_t size, MemoryHandler* memHandler, AllocationType
2
2091
by: Dave | last post by:
Hello all, I'd like to find a source on the web that discusses, in a comprehensive manner and in one place, everything about new / delete. It should include overloading operator new, the new operator, placement, nothrow, arrays, etc... My books cover the topic, I've found FAQs on the web that cover the topic, and so on, but all the sources I've found are disjointed. There's a bit on this page, a bit on that page, and so on. The...
1
1519
by: scorpiotgs | last post by:
I downloaded a script for a menu (below) but I want all the links i this part(ze_menu3) to open in a new window. this probably a noob question, but i couldnt figure it out, so pleas help me "ez_Menu= new Array("cbg.nl~Centraal Bureau voor Genealogie te De Haag^http://www.cbg.nl", "genlias.nl^http://www.genlias.nl" "rijksarchieflimburg.nl^http://www.rijksarchieflimburg.nl" "deschoolbank.nl^http://www.deschoolbank.nl"...
15
4662
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any field to start. If I edit that field and then click on the new record button in the navigation buttons, the form goes to a new record and each field has the default value of the previous record. If I put the focus in any field to start, edit that...
7
2479
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls each with a couple of controls in them I then rebuilt my project and my new panels and all controls they contained are gone... I've looked through the Auto generated code but don't see anything that looks wrong Any body have any idea why this...
3
1891
by: Grizlyk | last post by:
Hi, people. Can anybody explain me "multiple 'new' at single line" behavior. Consider: p::p(void*); p::p(void*,void*); new A( p(new B), p( new C(p(new D), p(new E)) ), p(new F));
0
9641
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10146
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.