[Python-ideas] Fast sum() for non-numbers - why so much worries?
David Mertz
mertz at gnosis.cx
Fri Jul 12 23:33:46 CEST 2013
I think I've followed every post in this long thread and the spinoffs. I
don't want to try to address all the small points and sub-threads. Here's
my overall take-away:
* Using 'sum()' to concatenate sequences or iterators is unintuitive,
inferior to other existing techniques, and any code that does so is already
*slightly* "broken." (stylistically, not functionally necessarily).
Given my perception in the above bullet, I would be +1 on deprecating this
use altogether (i.e. raise DeprecationWarning if a good way could be found
to distinguist "sequence" from "some other thing that implements .__add__()
and is numerical enough"). Even if there's no practical way to make that
distinction in a duck-typed language, the documentation should (continue
to) say "sum() is the wrong way to concatenate sequences". I am -1 on
modifying the semantics of sum() to use .__iadd__().
Even though we have TOOWTDI, in reality there are lots of Python constructs
that one *can* do, but really just *shouldn't*. Using sum() on sequences
feels about like ._getframe() hacks or slightly perverse generator
comprehensions on can write (e.g. for side-effects). We're all adults, and
we're not going to stop you (unless we do so with DeprecationWarning), but
it's just not the *right* thing to do.
David...
--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons. Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130712/f61938b3/attachment-0001.html>
More information about the Python-ideas
mailing list