Why the 'self' argument?

John Roth newsgroups at jhrothjr.com
Sat Sep 6 00:23:36 CEST 2003


"Grant Edwards" <grante at visi.com> wrote in message
news:3f59014d$0$152$a1866201 at newsreader.visi.com...
> In article <vlhtm1bmc7m295 at news.supernews.com>, John Roth wrote:
>
> >> There's no difference in the sense that a method is simply a
> >> function whose first parameter refers to the class instance to
> >> be worked on.  No magic words, no "undeclared" parameters.  It
> >> means that in my demo code in limitcases.py (somewhere in the
> >> newsgroup lately) I can say
> >>
> >>     limitcases.Lowest.__str__ = lambda x: "-Infinity"
> >>
> >> to give the Lowest class a new method sans ennuis.
> >
> > But why do it that way?
>
> So that there's no difference between a function and a method.
>
> Simplicity and orthogonality are good things -- despite what
> C++ proponents thing.
>
> > Neither Java nor Ruby require giving the instance a name.
>
> So?
>
> Personally I don't like invisible, implied, automatic stuff
> like that.
>
> Can't stand automatic transmissions either -- the damn things
> have no idea what's ahead, and always seem to be in the wrong
> gear at critical moments.
>
> > Hence my comment that requiring it is more complex than not
> > requiring it.
>
> No, it's more complex the Java/Ruby way, since you have to have
> two sets of rules for what a name means depending on whether
> you're inside a "normal" function or a method.  In Python
> there's just one set of rules -- mostly.

As I said earlier, it's quite possible to define it so that there
is always an instance of some kind; whether that's an instance
a class or the module itself.

> I have enough trouble remembering how the stuff I design works. ;)
>
> I don't want to have to keep track of more scoping/name-space
> rules than absolutely necessary.

I think my comments have shown that you can reduce the
amount of scoping / name space rules noticably.

John Roth
>
> -- 
> Grant Edwards                   grante             Yow!  Intra-mural
sports
>                                   at               results are filtering
>                                visi.com            through th' plumbing...






More information about the Python-list mailing list