[Python-Dev] pyc files, constant folding and borderline portability issues

Andrew McNamara andrewm at object-craft.com.au
Tue Apr 7 09:43:37 CEST 2009

On 07/04/2009, at 7:27 AM, Guido van Rossum wrote:
> On Mon, Apr 6, 2009 at 7:28 AM, Cesare Di Mauro
> <cesare.dimauro at a-tono.com> wrote:
>> The Language Reference says nothing about the effects of code  
>> optimizations.
>> I think it's a very good thing, because we can do some work here  
>> with constant
>> folding.
> Unfortunately the language reference is not the only thing we have to
> worry about. Unlike languages like C++, where compiler writers have
> the moral right to modify the compiler as long as they stay within the
> weasel-words of the standard, in Python, users' expectations carry
> value. Since the language is inherently not that fast, users are not
> all that focused on performance (if they were, they wouldn't be using
> Python). Unsurprising behavior OTOH is valued tremendously.

Rather than trying to get the optimizer to guess, why not have a  
"const" keyword and make it explicit? The result would be a symbol  
that essentially only exists at compile time - references to the  
symbol would be replaced by the computed value while compiling. Okay,  
maybe that would suck a bit (no symbolic debug output).

Yeah, I know... take it to python-wild-and-ill-considered-ideas at python.org 

More information about the Python-Dev mailing list