A better self

Gabe Newcomb Gabe.Newcomb at noetix.com
Wed Jul 10 13:55:02 EDT 2002


It seems to me that, given that most folks here agree the concept of
'self' is useful, we may as well stick with the word 'self' as is. It's
the explicit version--it makes things clear, and if anyone's really
dying to use the shortest identifiers possible, they might consider
Perl.

Yes that last statement was partially tongue-in-cheek, but seriously,
readability is worth preserving IMO.

Gabe

-----Original Message-----
From: Huaiyu Zhu [mailto:huaiyu at gauss.almadan.ibm.com]
Sent: Wednesday, July 10, 2002 10:01 AM
To: python-list at python.org
Subject: Re: A better self


Sean 'Shaleh' Perry <shalehperry at attbi.com> wrote:
>> 
>> Before you all react (programmers can be SO conservative), please
think
>> about it!
>> 
>
>I have played with ideas like this in python and other languages, and
witnessed
>others do the same.
>
>.foo is REALLY hard to see if the font is not just right.
>
>.size = .r + .l
>
>is even worse.
>
>I am not 100% against the idea as an idea, but the actual usage is not
all that
>fun.

A better (and currently available) convention is

_.size = _.r + _.l

It has been mentioned several times in this thread.  I've used it
several
times in the past and liked it, esp in iterative algorithms.  Some usage
patterns include
    
    def __init__(_, x, y, z):
        _.x, _.y, _.z = x, y, z

    def process(_, x, y, z):
        actions involving _.x, _.y, _.z, x, y, z
        _.x, _.y, _.z = x, y, z

    def update(_):
        x, y, z = _.x, _.y, _.z 
        actions involving x, y, z
        _.x, _.y, _.z = x, y, z
    
One could even think of _. as a magic persistence prefix that makes the
variable keep its value between method calls.  It is also easy to
replace
_.x with self.x or vice versa in a good editor.

Huaiyu
-- 
http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list