Why read-only nested scopes?

Mike C. Fletcher mcfletch at rogers.com
Thu Sep 5 11:11:03 EDT 2002


 >>Why not simply disallow the using of a name already defined in an
 >>enclosing scope? Similar to Smalltalk?
 >
 >
 > That might break compatibility with existing code.

I'll go one further:
	That _would_ break large quantities of existing code.

#consider
def blah( somefile ):
	string = somefile.read()
	return string[1:-1]

is now dependent on string not being imported at a higher level? 
Perfectly predictable code, obviously no relationship to "string" in a 
higher scope, but suddenly raising errors.

#consider
class window:
	pass
def whah( window ):
	window.whah( someglobal, somenumber, something )

Which is now raising errors because the temp variable/argument matches 
the class-name (yes, I know, normally there's a case-diff, but the 
pattern happens with types and the like).

If, for some reason this functionality (assigning to an enclosing scope 
which is not global (does this really occur much? I've never felt such a 
need that I can recall)), figure out a better way, such as:

	global(2) x

(Yes, ugly, but doesn't kill lots of code).  Or:

	global existing x

where the existing form says that an existing x record must be used.

But please sirs, don't kill our code :) ,
Mike

Martin v. Löwis wrote:
> "Jay O'Connor" <joconnor at cybermesa.com> writes:
> 
> 
>>Why not simply disallow the using of a name already defined in an
>>enclosing scope? Similar to Smalltalk?
> 
> 
> That might break compatibility with existing code.
> 
> Regards,
> Martin
_______________________________________
   Mike C. Fletcher
   Designer, VR Plumber, Coder
   http://members.rogers.com/mcfletch/






More information about the Python-list mailing list