optimization question

Steve Holden sholden at holdenweb.com
Tue Aug 13 05:19:18 CEST 2002

"Andrew Koenig" <ark at research.att.com> wrote ...
> >> Doesn't string qualify?
> Steve> Only before you subclass it to optimize slicing.
> Sorry -- my question was too terse.  I'll elaborate:
> My understanding is that because strings are immutable, any Python
> implementation is permitted to disregard object identity when
> it computes string values.  So, if I write
>         a = "hello, world"
>         b = a[0:5]
> the implementation is permitted to cause a and b to refer to two
> different subsequences of the same part of memory.  I understand that
> present implementations do not behave this way in general, but I don't
> think there's any basis for assuming that no implementation will ever
> behave this way.  Am I right?

Yes. And now I understand you to mean that the same would be true for any
immutable sequence type. While the implementation details would be complex
there's nothing in Python's semantics to stop you from doing that.

Just to get back to your original question, might it not make more sense to
build the program using a function call or equivalent to start with? Seems
it would be much easier to go from a function call to inline code than vice
versa were such a change to be necessary for optimization reasons. Also much
less likely to be inappropriately corrected (since the form you are seeking
to optimize will obviously appear in other contexts too).

While the deep thought you are clearly accustomed to putting into your
designs is necessary to make program structures sufficiently simple, too
much of it might prevent you from implementing anything at all!

Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/

More information about the Python-list mailing list