too many self
aurora
aurora00 at gmail.com
Thu Sep 16 15:56:39 EDT 2004
Peter Hansen wrote:
> aurora wrote:
>
>> On Wed, 15 Sep 2004 23:14:47 +0200, Diez B. Roggisch
>>
>>> class ThreadPrinter:
>>> def __init__(self):
>>> _.fhs = {}
>>>
>>> def write(self, value):
>>> f = _.fhs.get(threading.currentThread(),
>
> ....
>
>> Thanks this is a nice idea. I hope Python would actually support the
>> '_' syntax. The self really reduce readablity, especially if you have
>> several of them in one line.
>
>
> It does! One just has to be consistent within each function.
> Diez changed the code from something like this:
>
> def __init__(_):
> _.fhs = {}
>
> def write(_, value):
> f = _.fhs.get(threading.currentThread(),
> ...
>
> Some would argue that this is actually less readable, however,
> since it uses punctuation instead of a word. If nothing else,
> you run into a bit of a conflict between your own technique,
> with "_", and the vast majority of the rest of the Python world,
> which uses "self" exclusively, leading to situations like this
> one...
>
> (I think if I had a routine that really heavily used self,
> to the obvious detriment of readability, and it wasn't clear
> how else to improve it, I would use a local assignment at
> the top to make a shorter name, perhaps "s", or even "_" --
> but I wouldn't use the possibility of such a thing as a
> justification for using _ everywhere.)
>
> -Peter
Didn't aware that _ itself is a valid identifier! True, you don't really
want to do things differently from convention. I'm just ranting about
the verbosity of self.
This doesn't take a complicated statement to make it really clumsy. Some
simple statement would look like this:
if self.max < self.list[self.index]:
self.max = self.list[self.index]:
Replacing self with _, depends on one's aesthetic, it could be ugly or
it could be cleaner. I like it that it is not a word and it does not
interfere with the keywords that's really relevant.
if _.max < _.list[_.index]:
_.max = _.list[_.index]:
Of couse I think this syntax the best:
if max < list[index]:
max = list[index]:
This remind me of those awful Hungarian notation.
aurora
More information about the Python-list
mailing list