A better self

Grant Griffin not.this at seebelow.org
Fri Jul 19 15:24:08 EDT 2002


In article <3D385A46.6DC47857 at astro.cornell.edu>, Tom says...
>
>"Louis M. Pecora" wrote:
>> 
>> Many people have suggested doing something like the following (which is
>> reasonable) to eliminate self. from mathematical expressions:
>> 
>>   t, x, y, z=self.t, self.x, self.y, self.z
>>   result=sin(t)*x**y+sqrt(z)  # A pretend formula
>
>Yes, this was suggested earlier.  I don't consider it a great solution
>to the problem.  For example, in a current calculation I have a class
>with many member variables and many member functions that use them
>to return various quantities.  In a language that boasts of how

I don't remember any "boasting".  Python is for the humble (except for maybe Tim
and Fredrik <wink>).

>simple and straightforward it is, and how it shrinks code size (by
>omitting braces, declarations, etc.), it is rather silly to have 
>lines like:
>
>   t, x, y, z=self.t, self.x, self.y, self.z
>
>in every one of many member functions, often with the same variables.
>You look at that code, with all those redundant lines of negligible
>content, and it yells out to you:  something is missing here that
>should make this silly copying unnecessary in order to have expressions
>that are easy to read/understand.
>
>The language is so great in other respects, and on a fundamental level
>the arguments for "self." are so sound, that I just live with this.
>But it sure is a nuisance.

I was thinking about this just a few days ago.  I had found a book about Ada on
our "unloved software books" shelf at work.  (In fact, there were six copies of
it, so Ada must be pretty unloved <wink>.)  I read a little of it, and it turns
out that Ada provides "with", which is the one-and-only construct I missed when
I moved from Pascal (Ada's daddy) to C many years ago.

For example:

   with self:
      result=sin(t)*x**y+sqrt(z)  # A pretend formula

I don't know if there's a technical reason (in terms of either Python grammar or
C implementation) why this wouldn't work, but perhaps it's not in Python
because:

   1) explicit is better than implicit
   2) there should be one--and preferably only one--way to do things

or maybe even

   3) it hasn't happened yet

(At one time, I used to think "augmented assignment" was left out of Python
because of 1) and 2), but it turned out to be 3).  Silly me <wink>.)

any-construct-that's-in-pascal-and-ada-but-not-in-C
   -can't-be-all-bad-<wink>-ly y'rs,

=g2

or, as we would say in Pascal:

:=g2

_________________________________________________________________________

Grant R. Griffin                                           g2 at dspguru.com
Publisher of dspGuru                               http://www.dspguru.com
Iowegian International Corporation                http://www.iowegian.com




More information about the Python-list mailing list