[pypy-dev] [Python-Dev] efficient string concatenation (yep, from 2004)

Steven D'Aprano steve at pearwood.info
Thu Feb 14 01:35:34 CET 2013


On 14/02/13 01:44, Nick Coghlan wrote:

> Deliberately *relying* on the += hack to avoid quadratic runtime is
> just plain wrong, and our documentation already says so.

+1

I'm not sure that there's any evidence that people in general are *relying* on the += hack. More likely they write the first code they think of, which is +=, and never considered the consequences or test it thoroughly. Even if they test it, they only test it on one version of one implementation on one platform, and likely only with small N.

Besides, if you know that N will always be small, then using += is not wrong.

I think we have a tendency to sometimes overreact in cases like this. I don't think we need to do any more than we are already doing: the tutor@ and python-list@ mailing lists already try to educate users to use join, the docs recommend to use join, the Internet is filled with code that correctly uses join. What more can we do? I see no evidence that the Python community is awash with coders who write code with atrocious performance characteristics, or at least no more than any other language.



-- 
Steven


More information about the pypy-dev mailing list