Hi all, I came across the following performance issue with the sum function while summing lists: https://bugs.python.org/issue18305 It's been discussed previously in this list and other issues. The rationale in that ticket makes the case that performance won't be fixed because sum() should not be treated as a generic way to concatenate sequences (and there is documentation saying this). Having non-linear complexity is not a suitable way to discourage this behaviour though. Non-linearity is hard to detect in testing and development, so is more likely to lead to performance bugs in libraries and production, than to discourage use from the outset. Moreover, it is confusing to end users to have a feature while discouraging its use through a somewhat passive-aggressive runtime. New users, and experienced users who do not pour through the documentation will use sum because it supports this API, and one would assume that's intentional. On the other hand, the behaviour for strings is a far superior user-experience. When attempting to use sum() on strings, users are presented with a TypeError and a handy tip (use "".join(seq) instead). It is clear to users that they are attempting an anti-pattern and how to correct it. So I propose moving (eventually) to the same system with lists as for strings. Or else removing the performance trip-hazard from the sum function with lists. Best regards, Oliver
participants (21)
-
Ben Rudiak-Gould
-
Chris Angelico
-
Christopher Barker
-
Damian Shaw
-
David Mertz
-
Greg Ewing
-
Guido van Rossum
-
Jelle Zijlstra
-
Marc-Andre Lemburg
-
Mathew Elman
-
MRAB
-
Neil Girdhar
-
Oliver Margetts
-
Oscar Benjamin
-
Paul Svensson
-
Ricky Teachey
-
Rob Cliffe
-
Sebastian Berg
-
Serhiy Storchaka
-
Stephen J. Turnbull
-
Steven D'Aprano