A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-February/051442.html below:

[Python-Dev] list of constants -> tuple of constants

[Python-Dev] list of constants -> tuple of constantsSkip Montanaro skip at pobox.com
Sun Feb 6 17:49:05 CET 2005
In a python-checkins message, Raymond stated:

    Raymond> Replace list of constants with tuples of constants.

I understand the motivation here (the peephole optimizer can convert a tuple
of constants into a single constant that need not be constructed over and
over), but is the effort worth the cost of changing the logical nature of
the data structures used?  If lists are conceptually like vectors or arrays
in other languages and tuples are like C structs or Pascal records, then by
converting from list to tuple form you've somehow muddied the data structure
water just to take advantage of tuples' immutability.

Wouldn't it be better to have the peephole optimizer recognize the throwaway
nature of lists in these contexts:

    for elt in [1, 2, 4, 8, 16]:
        ...

    if foo in [list, tuple]:
        ...

(anywhere a list of constants immediately follows the "in" or "not in"
keywords) and convert them into constants?  The cases you converted all
matched that usage.

Skip

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4