A better self
Louis M. Pecora
pecora at anvil.nrl.navy.mil
Fri Jul 19 10:18:04 EDT 2002
Yes, I agree with all that's said below (I do almost strictly numerical
stuff so I feel the pain of self. -- sheeze, that was almost Zen). But
I agree with Tom Loredo that there are good general arguments for self.
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
My question is how much overhead is added by the assignments in the top
line? I suspect not much at all, but then I do not know how the
interpreter handles these things.
-- Lou Pecora
In article <3D3724C0.F3286A11 at astro.cornell.edu>, Tom Loredo
<loredo at astro.cornell.edu> wrote:
> Huaiyu Zhu wrote:
> >
> > However, there are situations, mostly in numerical computations, where it is
> > necessary to have, say, a dozen variables in one expression, and a dozen
> > statements containing such expressions and some other statements in one
> > method. It is far more readable to have them all appear in one screen in a
> > form that resembles written equations on paper, than to dogmatically follow
> > a convention in a particular programming language.
>
> Extremely well put.
>
> I've been using Python almost exclusively for scientific programming in
> the past 3 years or so. I've followed threads about many controversial
> aspects of Python (additions or long-held characteristics), and I've
> been impressed time after time with the choices of the development team.
> Even when my first instinct has been to disagree with a choice or policy,
> I have always come to see a great deal of wisdom in the final choice.
>
> But the one thing that continues to irk me about the language is "self,"
> for just the reasons Huaiyu describes. I think non-numerical programmers
> are likely not in a position to appreciate the awkwardness of "self..."
> in numerical settings, where in a many-variable expression it serves
> to hinder understanding (by making the expression very long, often
> broken across multiple lines) rather than to enhance it. Yet I think the
> general arguments for "self" are strong and valid. Though I often wish there
> were something like a "with" statement in such contexts, Huaiyu's
> suggestion seems like a reasonable middle ground.
>
> But if there were a "with" statement, I'd probably welcome it!
>
> Cheers,
> Tom Loredo
More information about the Python-list
mailing list