Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'yet.': 0.04; 'argument': 0.05; 'attribute': 0.07; 'method.': 0.07; 'think,': 0.07; 'callback': 0.09; 'file)': 0.09; 'lookup': 0.09; 'oop': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'language.': 0.14; '>>': 0.16; 'argument.': 0.16; 'example)': 0.16; 'foo()': 0.16; 'internals,': 0.16; 'is;': 0.16; 'which,': 0.16; 'wrote:': 0.18; "hasn't": 0.19; 'passing': 0.19; 'not,': 0.20; '8bit%:5': 0.22; 'input': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'convenient': 0.24; 'lets': 0.24; 'pointer': 0.24; 'skip:` 20': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; '(see': 0.26; 'pass': 0.26; 'somewhere': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'feature': 0.29; '[1]': 0.29; 'said,': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'that.': 0.31; '13,': 0.31; 'enabled': 0.31; 'gcc': 0.31; 'terms.': 0.31; 'class': 0.32; 'languages': 0.32; 'url:python': 0.33; 'sense': 0.34; "can't": 0.35; 'received:209.85': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'c++': 0.36; 'done': 0.36; 'url:listinfo': 0.36; "didn't": 0.36; 'method': 0.36; 'url:org': 0.36; 'should': 0.36; 'received:209': 0.37; 'clear': 0.37; 'easily': 0.37; 'starting': 0.37; 'whatever': 0.38; 'pm,': 0.38; 'that,': 0.38; 'ability': 0.39; 'does': 0.39; 'bad': 0.39; 'extremely': 0.39; 'functional': 0.39; 'url:mail': 0.40; 'read': 0.60; 'most': 0.60; 'mentioned': 0.61; "you're": 0.61; 'first': 0.61; 'to:addr:gmail.com': 0.65; 'invalid': 0.68; 'subject:skip:o 10': 0.84; 'exposing': 0.91; '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:cc:content-type; bh=/ptYYWCwzp94Skbr3wbJbSysTNqSBqNK+WzQNrSSIdU=; b=pqAdHOX+wte2l5bzYIsH6W2gkgIKOOnaPbAiGn5t1XfKNZJY5/M9GDBVqwITypHXu1 iiWxG5YWRnzlW7fvI75a82AloefNoU4FwWs9OxLiCxN2j1TtaQM92888juXdz1TxUJME Sm+XoDujQYF4GPRm4fdpjSkXrioVyjOTTx9ynKQWLUKX7JiV7XdJLCCBcIL62z//fQJH k1KIT//KGtdHxOxGR54AUX4L3RaNpgfLu2XiNiOCl93BVfEFveRzTpCW5stho+h+Q59D x7INXGPi3FKgbsyUdimP/bXTbn4wG/xmE3V/S7uIB9adNo9b9tW6b1CJT/t9FTCsKUoI gzdg== MIME-Version: 1.0 X-Received: by 10.229.67.4 with SMTP id p4mr8572762qci.44.1368432577726; Mon, 13 May 2013 01:09:37 -0700 (PDT) In-Reply-To: References: <518a123c$0$11094$c3e8da3@news.astraweb.com> <51902332.8090301@canterbury.ac.nz> Date: Mon, 13 May 2013 09:09:37 +0100 Subject: Re: object.enable() anti-pattern From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: Chris Angelico Content-Type: multipart/alternative; boundary=001a11c2ef78b1d8f804dc950918 Cc: python-list@python.org 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: 127 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368432969 news.xs4all.nl 15877 [2001:888:2000:d::a6]:34722 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45228 --001a11c2ef78b1d8f804dc950918 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 13 May 2013 08:40, "Chris Angelico" wrote: > > 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. After > > all in most languages `self` / `this` / whatever is not an argument to every > > 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-attri= bute-format-printf-x-y-inside-a-class > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list I know ECMAScript does that. It would be nice to be able to pass an instance method as a callback argument without using `.bind(theInstance)`. At any rate, exposed or not, that is all still internals. Exposing the ability to set the ` this ` as an argument is, I think, a functional feature (map(str.strip, file) is a good example) That said, I didn't know c++ did that, but it makes sense with what I read somewhere about c++ starting out as a transcompiler-to-c-based language. --001a11c2ef78b1d8f804dc950918 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


On 13 May 2013 08:40, "Chris Angelico" <rosuav@gmail.com> wrote:
>
> On Mon, May 13, 2013 at 4:32 PM, F=E1bio Santos <fabiosantosart@gmail.com> wrote:
> >
> > On 13 May 2013 00:22, "Greg Ewing" <greg.ewing@canterbury.ac.nz> wrote: > >> The same argument can be applied to:
> >>
> >> =A0 =A0foo =3D Foo()
> >> =A0 =A0foo.do_something()
> >> =A0 =A0foo.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 O= OP terms. After
> > all in most languages `self` / `this` / whatever is not an argume= nt to every
> > method.
>
> Yes, it is; it's just often implicit. C++ lets you poke around wit= h
> the internals, and it's pretty clear that 'this' is an arg= ument. (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 turn= s an
> attribute lookup on an instance into an attribute lookup on the class<= br> > plus a currying. One way or another, the bit-before-the-dot is an
> argument to the function.
>
> [1] http://stackover= flow.com/questions/11621043/how-should-i-properly-use-attribute-format-prin= tf-x-y-inside-a-class
>
> ChrisA
> --
> http:/= /mail.python.org/mailman/listinfo/python-list

I know ECMAScript does that. It would be nice to be able to = pass an instance method as a callback argument without using `.bind(theInst= ance)`.

At any rate, exposed or not, that is all still internals. Ex= posing the ability to set the ` this ` as an argument is, I think, a functi= onal feature (map(str.strip, file) is a good example)

That said, I didn't know c++ did that, but it makes sens= e with what I read somewhere about c++ starting out as a transcompiler-to-c= -based language.

--001a11c2ef78b1d8f804dc950918--