Why self?

Andrae Muys amuys at shortech.com.au
Tue Jul 9 21:39:32 EDT 2002


"Louis M. Pecora" <pecora at anvil.nrl.navy.mil> wrote in message news:<090720021439257166%pecora at anvil.nrl.navy.mil>...
> [[ This message was both posted and mailed: see
>    the "To," "Cc," and "Newsgroups" headers for details. ]]
> 
> In article <mailman.1026238754.7837.python-list at python.org>, Mark
> McEahern <marklists at mceahern.com> wrote:
> 
> > What you don't see, of course, is all the people who are silent because
> > they're quite happy with self. prefixes and consider this a pointless
> > discussion usually kept alive by people who refuse to learn the idioms of
> > Python to their best advantage.
> 
> Yeah, I may be one of those complainers.  I have tried to learn the
> language well and really like it, but for some reason this self. thing
> really bugs me.  (I _am_ seeing a therapist :-)  ).  I write a lot of
> scientifc code and I just think
> 
> 
>    self.y= self.x**2 * self.t/self.z + self.a * FFT(self.tseries)
> 
> is a LOT uglier than
> 
>    y= x**2 * t/z + a * FFT(tseries)

In fact the only reason I have followed this thread is because I found
myself writing some similar code just the other day and came to the
same conclusion.  Python loves namespaces right?  Now I haven't given
much thought to it, but it occurs to me to ask why Python dosn't
provide support for using namespaces, not just defining them?

Compare the following:

self.y= self.x**2 * self.t/self.z + self.a * FFT(self.tseries)

to:

y= x**2 * t/z + a * FFT(tseries)

to:

with self:
    y= x**2 * t/z + a * FFT(tseries)

Issues that immediately occur to me are:

1) Another keyword
2) How do you reference variables that aren't in the specified
namespace without a second keyword!
3) Issue 2 becomes critical when you what to deal with temporary
results that you definately want discarded along with the current
local scope.  So maybe only rvalues are affected ie.

with self:
    self.y = x**2 * t/z + a * FFT(tseries)

might be better, but then the inconsistency bites.

Maybe this is a good idea?  More likely I'm about to learn which
critical basic flaw I've missed.

at-least-I-will-get-to-learn-something-ly yours

Andrae Muys



More information about the Python-list mailing list