Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'classes,': 0.05; 'classes.': 0.07; 'python': 0.09; 'considered,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sep': 0.09; 'classes:': 0.16; 'code?': 0.16; 'descriptors,': 0.16; 'inheritance': 0.16; 'new-style': 0.16; 'old-style': 0.16; 'properties,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'simplified': 0.16; 'still,': 0.16; 'subject:class': 0.16; 'trivially': 0.16; 'wrote:': 0.17; 'widely': 0.17; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.28; '-0700,': 0.29; "d'aprano": 0.29; 'steven': 0.29; 'yes.': 0.29; 'skip:_ 10': 0.29; 'classes': 0.30; 'code': 0.31; 'from:addr:yahoo.co.uk': 0.32; 'not.': 0.32; 'correctly.': 0.33; 'to:addr:python-list': 0.33; 'thanks': 0.34; 'awesome': 0.35; 'subject:?': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'correctly': 0.37; 'two': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'some': 0.38; 'things': 0.38; 'to:addr:python.org': 0.39; 'subject:-': 0.40; 'header:Received:5': 0.40; 'future.': 0.62; 'needing': 0.62; 'advantages': 0.71; 'delegation': 0.84; 'pain': 0.84; 'reminder,': 0.84; 'received:2': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: new-style class or old-style class? Date: Tue, 25 Sep 2012 19:45:37 +0100 References: <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com> <5061d9db$0$29981$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-2-97-76-241.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 In-Reply-To: <5061d9db$0$29981$c3e8da3$5496439d@news.astraweb.com> X-Antivirus: avast! (VPS 120925-0, 25/09/2012), Outbound message X-Antivirus-Status: Clean X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348598713 news.xs4all.nl 6948 [2001:888:2000:d::a6]:41492 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30118 On 25/09/2012 17:20, Steven D'Aprano wrote: > On Tue, 25 Sep 2012 07:44:04 -0700, Jayden wrote: > >> In learning Python, I found there are two types of classes? Which one >> are widely used in new Python code? > > New-style classes. > >> Is the new-style much better than old-style? > > Yes. > > Always use new-style classes, unless you have some specific reason for > needing old-style ("classic") classes. > > Advantages of new-style classes: > > 1) They are the future. In Python 3, all classes are "new-style" and > classic classes are gone. > > 2) Multiple inheritance works correctly. Multiple inheritance for classic > classes is buggy. > > 3) New-style classes support awesome features like super(), properties, > descriptors, and __getattribute__. Old-style do not. > > The main disadvantage is that automatic delegation is a pain to do > correctly in new-style classes, but trivially simple in classic classes. > Still, all things considered, it's a good trade. > > > Thanks for this reminder, my port of the J word code to Python has just been simplified :) -- Cheers. Mark Lawrence.