help on ultra newbie program please
Andrew Walkingshaw
andrew-usenet at lexical.org.uk
Thu May 22 18:58:12 EDT 2003
In article <75aza.123981$3n5.27539 at news2.central.cox.net>, Steve Holden wrote:
[initializing variables]
> That seems a bit strange (though I cannot claim to b e the universal
> arbitrator of what's strange and what's not). You seem to be saying that, to
> avoid AttributeError exceptions due to not having initialized your variables
> before you use them, you initialize them at the start of your code.
That wasn't what I meant, really; it's kind of imprecise what I did
mean, which is making it clear to me that I was thinking fuzzily at the
time, but the kind of thing I mean is something like:
def dbrent(f, df, ax, bx, cx, tol = 0.001, maxiter = 100,
zeps=1e-10, fuzz=1e-10):
""" Brent line search using derivatives. """
a = b = d = d1 = d2 = du = dv = dx = dw = e = 0.0
... etc ...
All these get clobbered almost immediately - they're all
temporary variables - but it seemed useful to me, optically,
to list what the temporary variables *were* in this function "up front".
This is probably bad programming practice - I'm more than
willing to listen to the assembled wisdom on this.
I'm certainly not talking about defining a whole stack of variables in
global scope, or anything else equally bizarre - that seems to me to be
more likely to cause a whole lot of bugs, rather than prevent them.
My apologies for any confusion,
- Andrew
--
Andrew Walkingshaw | andrew-usenet at lexical.org.uk
More information about the Python-list
mailing list