const for bytecode optimization...

Michal Wallace sabren at manifestation.com
Fri Feb 11 15:02:23 EST 2000


hey all,

you know... I was just thinking... someone posted about the const operator
a day or two ago... and the response was generally that you don't need it
because you can do THIS_KINDA_THING or even const.this ....

But there's another thing that const gets you... Java, for example, can use
static final variables (constants) as a sort of bytecode optimizer, in place
of c style #IFDEF 's

for example, say you had:

DEBUG = 0

# call various functions any one of which might change DEBUG

if DEBUG:
    # nothing in here needs to be compiled into the .pyc
    pass

from what I understand, the optimizing compiler doesn't do anything yet,
maybe this could be a start..

of course, you could also just enforce the ALL_CAPS as being
constant, and not allow them to be redefined, but this could break
someone's code if they didn't follow that convention...

thoughts?

-michal
http://www.sabren.com/






More information about the Python-list mailing list