Proposal: local variable declarations and type advice

Paul Rubin phr-n2002a at nightsong.com
Wed Feb 27 05:08:21 EST 2002


"Terry Reedy" <tjreedy at home.com> writes:
> > Local variable declarations are for code cleanliness.  Currently, using
> > some name for a temp variable leaves detritus around after you're done
> > with it.  To figure out what the program is doing, you have to check
> > whether further references to 'temp' really wanted the value left from
> > someplace far away, or were holding just a different temporary value.
> > When the usefulness of a variable ends, its scope should also end.
> 
> An explicit 'del temp' ends the scope of the variable.  Its not much
> more to type that any sort of brackets and allows for overlapping
> scope of temporaries instead of artificially forcing nesting.  If you
> want to extend the scope of 'temp', it is probably easier to get rid
> of the explicit deletion than a pair of brackets.

"del temp" ends the inner scope by destroying the outer scope!  That's
throwing the baby out with the bathwater.  Sorry, no cigar.  It's
really a deficiency that there's no way to create a new local scope.

Also, there's no way to make sure that the "del temp" at the end of
a block actually gets run, unless you put try...finally around it,
which is a big mess.



More information about the Python-list mailing list