On 13 May 2013 08:40, "Chris Angelico" <ros...@gmail.com> wrote: > > On Mon, May 13, 2013 at 4:32 PM, Fábio Santos <fabiosantos...@gmail.com> wrote: > > > > On 13 May 2013 00:22, "Greg Ewing" <greg.ew...@canterbury.ac.nz> wrote: > >> The same argument can be applied to: > >> > >> foo = 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-attribute-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.
-- http://mail.python.org/mailman/listinfo/python-list