[ python-Feature Requests-1465406 ] Allowing the definition of constants

SourceForge.net noreply at sourceforge.net
Thu Apr 6 01:30:06 CEST 2006


Feature Requests item #1465406, was opened at 2006-04-05 23:30
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1465406&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Parser/Compiler
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Chris Wilson (ciw42)
Assigned to: Nobody/Anonymous (nobody)
Summary: Allowing the definition of constants

Initial Comment:
One of the current optimizations due in v2.5 includes
constant folding of expressions, which as it stands
serves as a way of somply getting rid of a redundant
arithmetic operations and the like.

In practice, it's rare a developer would leave an
expression such as "2+3" sat in his/her code, but by
allowing the declaration of constants within a script,
it could make this new feature *much* more useful.

As an example, in a recent script I had the following
at the top, outside the main loop:

SCREEN_WIDTH=640
SCREEN_HEIGHT=480
SCREEN_RATIO=SCREEN_WIDTH/SCREEN_HEIGHT

As SCREEN_RATIO is used a number of times during my
main loop, it makes sense to pre-calculate it to avoid
the extra processing, but if the compiler were aware
that SCREEN_WIDTH and SCREEN_HEIGHT were constants, it
could optimise out the calculation and I could include
the calculation in-place.

I frequently make use of "constants" to make my code
more readable, and wonder whether there is any
performance penalty or lack of optimisation going on
due to them in fact being regular variables?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1465406&group_id=5470


More information about the Python-bugs-list mailing list