[Python-ideas] Create a StringBuilder class and use it everywhere
Steven D'Aprano
steve at pearwood.info
Thu Aug 25 16:00:40 CEST 2011
Mike Graham wrote:
> On Thu, Aug 25, 2011 at 5:28 AM, k_bx <k.bx at ya.ru> wrote:
>> def main_bucket():
>> b = StringBuilder(u"initial value ")
>> for i in xrange(30000000):
>> b += u"more data"
>> return unicode(b)
>
> This doesn't seem nicer to read and write to me than the list form. I
> also do not see any reason to believe it will stop people from doing
> it the quadratic way if the ubiquitous make-a-list-then-join idiom
> does not.
Agreed. Just because the Java idiom is StringBuilder doesn't mean Python
should ape it. Python already has a "build strings efficiently" idiom:
''.join(iterable_of_strings)
If people can't, or won't, learn this idiom, why would they learn to use
StringBuilder instead?
--
Steven
More information about the Python-ideas
mailing list