[Python-Dev] PATCH submitted: Speed up + for string concatenation, now as fast as "".join(x) idiom
Ron Adam
rrr at ronadam.com
Sat Oct 7 06:23:00 CEST 2006
Nicko van Someren wrote:
> On 6 Oct 2006, at 12:37, Ron Adam wrote:
>
>>>> I've never liked the "".join([]) idiom for string concatenation; in my
>>>> opinion it violates the principles "Beautiful is better than ugly." and
>>>> "There should be one-- and preferably only one --obvious way to do
>>>> it.".
> ...
>> Well I always like things to run faster, but I disagree that this
>> idiom is broken.
>>
>> I like using lists to store sub strings and I think it's just a matter of
>> changing your frame of reference in how you think about them.
>
> I think that you've hit on exactly the reason why this patch is a good
> idea. You happen to like to store strings in lists, and in many
> situations this is a fine thing to do, but if one is forced to change
> ones frame of reference in order to get decent performance then as well
> as violating the maxims Larry originally cited you're also hitting both
> "readability counts" and "Correctness and clarity before speed."
The statement ".. if one is forced to change .." is a bit overstated I think.
The situation is more a matter of increasing awareness so the frame of reference
comes to mind more naturally and doesn't seem forced. And the suggestion of how
to do that is by adding additional functions and methods that can use
lists-of-strings instead of having to join or concatenate them first. Added
examples and documentation can also do that as well.
The two ideas are non-competing. They are related because they realize their
benefits by reducing redundant underlying operations in a similar way.
Cheers,
Ron
More information about the Python-Dev
mailing list