Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'yet.': 0.04; 'argument': 0.05; 'attribute': 0.07; 'method.': 0.07; 'lookup': 0.09; 'oop': 0.09; 'received:mail-vc0-f174.google.com': 0.09; 'python': 0.11; 'argument.': 0.16; 'foo()': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'internals,': 0.16; 'is;': 0.16; 'which,': 0.16; 'wrote:': 0.18; "hasn't": 0.19; 'passing': 0.19; 'input': 0.22; 'convenient': 0.24; 'lets': 0.24; 'pointer': 0.24; 'mon,': 0.24; '(see': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; '[1]': 0.29; 'message-id:@mail.gmail.com': 0.30; '13,': 0.31; 'enabled': 0.31; 'gcc': 0.31; 'received:209.85.220.174': 0.31; 'terms.': 0.31; 'class': 0.32; 'languages': 0.32; "can't": 0.35; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'c++': 0.36; 'done': 0.36; 'should': 0.36; 'received:209': 0.37; 'clear': 0.37; 'easily': 0.37; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'bad': 0.39; 'extremely': 0.39; 'to:addr:python.org': 0.39; 'most': 0.60; 'mentioned': 0.61; "you're": 0.61; 'first': 0.61; 'invalid': 0.68; 'subject:skip:o 10': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type:content-transfer-encoding; bh=70txkEYpOsIG5Mj6VqXrbbWfdPGYxsVrJP6CJScnjek=; b=TwFvOLjvYlFQ/bh6hjHon+hWh0YuezNo9WQUIzWTnd7x3HDwwBMxlUw0dcGMekEXDD ZQwgq8zuJoMjNWrp379VWABHvMhJHZ5prExeKyCBCZ6a+Xsx95uAmpHzjtyhm7Wo8tXS dTe/HGgsDQjXw73R3NIMbxz6PkWAOKnZocF2q7TAblInfDq7zqhU07bK8KEMtCqygDcX flomd+4DchXsAwfjScetpgKs6RIlD8GlsI/VM3IkRXeemmXauVcX+M7jUaJB6IuwMAb0 tqEx3oMsLEmzS0aES7RLqGqIWAry6b4XS2cbfsh3i3lYweBjaESnxj+1KQHGYWfYr5IL YIvA== MIME-Version: 1.0 X-Received: by 10.58.15.193 with SMTP id z1mr17671118vec.40.1368430601400; Mon, 13 May 2013 00:36:41 -0700 (PDT) In-Reply-To: References: <518a123c$0$11094$c3e8da3@news.astraweb.com> <51902332.8090301@canterbury.ac.nz> Date: Mon, 13 May 2013 17:36:41 +1000 Subject: Re: object.enable() anti-pattern From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368430610 news.xs4all.nl 15953 [2001:888:2000:d::a6]:56597 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45226 On Mon, May 13, 2013 at 4:32 PM, F=E1bio Santos = wrote: > > On 13 May 2013 00:22, "Greg Ewing" wrote: >> The same argument can be applied to: >> >> foo =3D Foo() >> foo.do_something() >> foo.enable() # should have done this first >> >> You're passing an invalid input to Foo.do_something, >> namely a Foo that hasn't been enabled yet. > > I don't think you can really count that as invalid input in OOP terms. Af= ter > all in most languages `self` / `this` / whatever is not an argument to ev= ery > method. Yes, it is; it's just often implicit. C++ lets you poke around with the internals, and it's pretty clear that 'this' is an argument. (See for instance what happens with the gcc 'format' attribute - I can't find a convenient docs page, but it's been mentioned on SO [1] and can be easily verified.) EMCAScript lets you call any function with any 'this' by using the .call() or .apply() methods - which, in my extremely not-humble opinionated opinion, is bad design (closures work implicitly, but the 'this' pointer doesn't??). Python turns an attribute lookup on an instance into an attribute lookup on the class plus a currying. One way or another, the bit-before-the-dot is an argument to the function. [1] http://stackoverflow.com/questions/11621043/how-should-i-properly-use-a= ttribute-format-printf-x-y-inside-a-class ChrisA