sum and strings

Paul Rubin http
Fri Aug 25 00:40:16 EDT 2006


Steven D'Aprano <steve at REMOVEME.cybersource.com.au> writes:
> There is an alternative: raise a warning instead of an exception. That
> permits the admirable strategy of educating users that join() is
> generally a better way to concatenate a large number of strings, while
> still allowing programmers who want to shoot themselves in the foot to do so.

This is reasonable, but why not just do the right thing and use the
right algorithm?  There is, after all, no guarantee in the docs that
''.join() uses the right algorithm either.  I've come to the view that
the docs should explicitly specify this type of thing, per the
Stepanov interview mentioned earlier.  You may be right that even when
it's not clear what the best algorithm is, using a correct but slow
algorithm is preferable to throwing an error.

But I think for strings, we should rethink how this kind of operation
is done, and build up the sum of strings in terms of some kind of mutable
string object resembling Java's StringBuf or Python's cStringIO objects.




More information about the Python-list mailing list