Python 3K or Python 2.9?

John Roth JohnRoth1 at jhrothjr.com
Fri Sep 14 17:58:43 EDT 2007


On Sep 12, 11:35 am, TheFlyingDutchman <zzbba... at aol.com> wrote:
> On Sep 12, 4:40 am, Bjoern Schliessmann <usenet-mail-0306.20.chr0n... at spamgourmet.com> wrote:
> > Ivan Voras wrote:
> > > What does "self" have to do with an object model? It's an
> > > function/method argument that might as well be hidden in the
> > > compiler without ever touching the role it has (if not, why?). I
> > > agree that it's needless noise in a language.
>
> > If this was needless, why do C++ and Java have the "this" pointer?
>
> "this" in C++ and Java is not shown in the parameter list, which was
> what he was
> complaining about.  He wants
>
> class MyClass:
>         def SomeFunction(someParameter):
>            self.someParameter = someParameter
>
> not
>
> class MyClass:
>         def SomeFunction(self, someParameter):
>            self.someParameter = someParameter
>
> The confusing way about the current Python method when you first
> encounter it is
>  why is "self" being passed in when you write the function but not
> when you call it. If the compiler is smart enough to know that
>
>     a = MyClass()
>     a.SomeFunction(12)
>
> SomeFunction() has a "self" implicitly added to the parameter list, it
> seems that it should be smart enough to know that a function defined
> in a class has a "self" implicitly added to the parameter list.

Pretty close. This is one of the things that's always puzzled me about
the discussion. Making self and cls keyword pseudo-constants that get
the current instance and class from the stack frame (or raise an
exception) would eliminate them from the method header.

It would ALSO eliminate a whole level of indirection in method
invocation and get rid of the instancemethod, classmethod and
staticmethod wrapper classes. This would be a significant
simplification. If it had been done earlier, it would have eliminated
most of the justification for method attributes (those silly @
things), thus showing that unneeded complexity breeds more unneeded
complexity.

John Roth




More information about the Python-list mailing list