variable declaration

Thomas Bartkus tom at dtsam.com
Tue Feb 1 10:13:36 EST 2005


"Carl Banks" <invalidemail at aerojockey.com> wrote in message
news:1107205410.367521.50490 at f14g2000cwb.googlegroups.com...
<snip>

> How common is it for a local variable to be bound in
> more than one place within a function?

How common?  It shouldn't happen at all and that was the point.
The original posters code demonstrates how it can occur inadvertently as a
result of a simple typographical error.

You won't hear me claim that Python is without mitigating virtues. Clearly,
there is much about Python that encourages good design which will in turn
reduce the incidence of such errors. Nevertheless, one has to admit to this
blemish.  One also wonders if it is really necessary to endure what looks to
me like an omission.  Is there a reason why the interpreter
couldn't/shouldn't require formal declarations?

I, too, wish there were a switch like VBs "Option Explicit" that would
require you to declare "epsilon = 0" and thereafter have the interpretor
refuse assignment to an undeclared "epselon". Sane VB programmers (and yes,
there are a few!) leave it on by default and consider it abomination that
the switch is optional. The original posters example was a good one.  I had
to take a good long stare before I saw it even though the code is short,
sweet, and otherwise correct.

*Is* there a reason why the interpreter couldn't/shouldn't require formal
variable declaration?
It seems to me that lack of same may also be creating hellish barriers to
writing truly effective IDEs for Python.

Thomas Bartkus





More information about the Python-list mailing list