Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'attributes': 0.05; 'instance': 0.05; 'distinction': 0.07; 'assumed': 0.09; 'exceptions': 0.09; 'labelled': 0.09; 'programmer': 0.10; 'c++': 0.12; 'class,': 0.15; 'preference': 0.15; "subject:' ": 0.15; 'clear.': 0.16; 'constructs': 0.16; 'from:addr:xs4all.nl': 0.16; 'instance)': 0.16; 'means:': 0.16; 'message-id:@xs4all.nl': 0.16; 'prepend': 0.16; 'rationale': 0.16; 'received:194.109': 0.16; 'received:194.109.24': 0.16; 'received:xs4all.nl': 0.16; 'syntactic': 0.16; 'x-mailer:apple mail (2.1084)': 0.16; 'syntax': 0.16; 'wrote:': 0.16; 'seems': 0.20; 'header:In-Reply-To:1': 0.22; 'default,': 0.23; 'pm,': 0.24; 'variable': 0.24; 'there.': 0.24; 'aug': 0.24; 'language.': 0.28; 'subject:need': 0.28; 'bit': 0.28; 'syntax,': 0.30; "skip:' 10": 0.30; 'class': 0.30; 'programmers': 0.31; 'subject:?': 0.31; 'there': 0.33; 'to:addr:python-list': 0.33; 'conventions': 0.34; 'curious': 0.34; 'weird': 0.34; 'charset:us-ascii': 0.36; 'instead.': 0.37; 'variables': 0.37; 'languages': 0.37; 'but': 0.37; 'some': 0.38; 'subject:: ': 0.39; 'received:192': 0.39; 'possible,': 0.39; 'header:Mime-Version:1': 0.39; 'why': 0.39; 'to:addr:python.org': 0.39; 'sense': 0.39; 'called': 0.40; 'where': 0.40; 'personal': 0.60; 'more': 0.60; 'your': 0.61; 'header:Message-Id:1': 0.61; '31,': 0.64; 'greetings': 0.72; 'yourself,': 0.74; 'fight': 0.80; 'ad-hoc': 0.84; 'methods?': 0.84; 'subject:always': 0.84; 'subject:class': 0.84; 'subject:self': 0.84; '"learn': 0.91 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1084) Subject: Re: Why do class methods always need 'self' as the first parameter? From: Michiel Overtoom In-Reply-To: <058cb764-2ba2-4b63-be4d-33307a9a81cc@g31g2000yqh.googlegroups.com> Date: Thu, 1 Sep 2011 13:23:54 +0200 Content-Transfer-Encoding: quoted-printable References: <0dc26f12-2541-4d41-8678-4fa53f347acf@g9g2000yqb.googlegroups.com> <058cb764-2ba2-4b63-be4d-33307a9a81cc@g31g2000yqh.googlegroups.com> To: PYTHON X-Mailer: Apple Mail (2.1084) X-Virus-Scanned: by XS4ALL Virus Scanner X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314876266 news.xs4all.nl 2518 [2001:888:2000:d::a6]:48755 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12561 > On Aug 31, 5:35 pm, "T. Goodchild" wrote: >> So why is 'self' necessary on class methods? >>=20 >> Just curious about the rationale behind this part of the language. When instance variables are accessed with the 'self.varname' syntax, it = is clear to the programmer that an instance variable is accessed, and = not some global. Other languages have weird syntax conventions like = that you have to prepend all instance attributes with an '@', and in = languages like C++ where there is not necessarily such a syntactic = requirement, many programmers use ad-hoc constructs like '_varname' or = 'm_varname' to make the distinction clear. >> It seems to me that the >> most common practice is that class methods *almost always* operate on >> the instance that called them. It would make more sense to me if = this >> was assumed by default, and for "static" methods (methods that are >> part of a class, but never associated with a specific instance) to be >> labelled instead. Yes, you have a point there. My personal preference would be to optimize = for the most common case, while exceptions to the norm are still = possible, but perhaps a bit more verbose. Greetings --=20 "Learn to value yourself, which means: fight for your happiness." - Ayn = Rand =20