Nested scopes hitch

Jeff Shannon jeff at ccvcorp.com
Mon Apr 8 20:43:54 EDT 2002


In article <mailman.1018310800.31349.python-list at python.org>, 
pinard at iro.umontreal.ca says...
> [Jeff Shannon]
> 
> > If you want access to variables inside of a function, you should 
> > pass those specific variables as arguments.  If you've got lots 
> > of arguments in common between lots of functions, assemble the 
> > lot into a class.  If neither of these is appropriate, then you 
> > should redesign -- you're using a very ugly approach.
> 
> I beg to disagree, a bit strongly.
> 
> Something is not ugly just because you prefer something else.  I have very,
> very neat applications which use globals() and locals(), and they will
> loose much if they use arguments all over, or get assembled into classes.

Very well, I suppose we will have to disagree, then.  To my mind, 
using globals() and locals() in this way is a gross violation of 
encapsulation.  As I see it, if there is data that truly needs to 
be accessed throughout an application (or subsystem), then it 
should be put in an explicit configuration dictionary or object 
(which could be either passed around, or set as global).  

I obviously can't speak to your specific designs, not having seen 
them, but I can't imagine how globals()/locals() would be 
necessary unless you have a large amount of interdependencies in 
your code, and it is generally accepted that interdependent code 
is not a good thing.  If you can explain to me how you can 
require access to large portions of another scope's namespace 
without having large interdependencies, then perhaps I'll change 
my mind about this method.

-- 

Jeff Shannon
Technician/Programmer
Credit International



More information about the Python-list mailing list