How do you create constants?

KevinL darius at bofh.net.au
Wed Nov 1 11:01:25 EST 2000


(Apologies in advance for longish email - the below has been bugging me for a 
while, I dunno whether it's my lack of understanding or actual "lackings" in 
python...  Probably the former)

>>> Steve Horne wrote
> Adding the const concept to a language when that language is already
> in widespread use is difficult to do well. Consider the problems that
> occur in well written C++, when you reach a level where you are
> calling into old C routines that don't have constant parameters tagged
> as const - real typecast hell!
> 
> Python is at heart a scripting language, and IMNSHO doesn't need
> paranoia constructs.

Hrm.  "Paranoia constructs" would be really useful for certain tasks - 
security in a multi-user system is my pet peeve here, you have to go to _so_ 
much trouble to re-create the concept of private namespaces in any really 
secure way.  Python's almost perfect to lean heavily on for providing a 
scripting engine - it's reflectiveness means an entity can tinker with the 
variables and methods of a live program from within that program itself, which 
makes exposing all that ability direct to users oh so tempting - until you 
realise that if you do so, you'll have a bugger of a time securing it all.  
So, you retreat back to bastioning tricks where you hide references in method 
definitions, bytecodehack code as it's "compiled" to disallow certain 
structures and subvert others (for an example, see Zope's PythonMethods 
bytecode trickery to make those secure), etc. etc.  Some of that bites 
especially because it forces you into call-within-call setups for certain 
functions, where python's method calls/frame setup&teardown seem kinda expensive
time-wise.

If you could pass data structures around between a core multi-user "engine" 
and the users themselves, safe in the knowledge that said structures were 
immutable - and I'm talking dictionaries and instances here, not just lists 
and tuples - then I reckon python'd really shine for that sort of work - 
because the language itself provides most of the tricks you need.  I know you 
can do that with instances, given restricted mode (hence no access to 
instance.__dict__), but you can't use instances in all the places you can use
dictionaries.

The only other problem that's always bugged me is an inability to reach the 
"caller" - the object that owns the method that called the current method, or 
even just a reference to the method that called the current method - in 
a secure (ie. non-subvertable) way, without playing more funky bastioning 
tricks, or without having total control of all the layers of code "above" you. 

IMHO, IANALanguage expert, I may be talking complete rubbish - but these are 
the problems I've run into trying to create my own little toy project.  I'd 
love to hear comment from some of the more knowledgeable people out there as 
to where I may be going wrong ;)  I guess at the heart, it feels as tho python's
always taking the view that "all the code is trustworthy", and I'd like to bend
it to running untrustworthy code within a trustworthy frame.

KevinL
http://www.bofh.net.au/





More information about the Python-list mailing list