Do I always have to write "self." ?
Louis M. Pecora
pecora at anvil.nrl.navy.mil
Fri Apr 28 13:46:58 CEST 2000
In article <slrn8ghc6t.f01.scarblac-spamtrap at flits104-37.flits.rug.nl>,
Remco Gerlich <scarblac-spamtrap at pino.selwerd.nl> wrote:
> No. However, this seems to make code *more* readable. In fact, many C++
> programmers use 'this.x' for all their instance variables, to be able to
> see at a glance which are just local variables of the function and which are
> instance variables. It's just more work to write, but that doesn't matter
I understand the potential for readability, but I do a lot of
mathematical programming so the expressions can get pretty cluttered
with variables and operators. More self's only makes it worse for me.
Maybe that's my problem, but then that's my complaint.
> Python needs it to know which vars are instance variables, and which are
> local variables.
I'm sure some way of declaring variables 'local' could be done in the
class defintion, but I doubt Guido would do that now.
> Funny how people say that every aspect of Python they don't like make the
> language less "clean". It is extremely consistent though.
Funny, I guess. Harder to read for me.
> You *can* use another word for 'self' though, 's' or 'me' or something. But
> it makes your code harder to read, of course...
You mean by doing something like
at the beginning of each class method?
More information about the Python-list