[Python-ideas] Fast sum() for non-numbers
Sergey
sergemp at mail.ru
Fri Jul 19 03:50:56 CEST 2013
On Jul 16, 2013 Stephen J. Turnbull wrote:
>> I don't understand it. It makes no sense to me.
>
> Just accept that many people, *for several different reasons*, dislike
> your proposal. The technical objections are the least of those
> reasons.
Sure, I already did. I just tried to understand, what part of my
proposal they don't like and why, in that case I could fix that part,
so that they liked id. If I don't understand — I don't know what
to fix.
> Please just write the PEP and ask for a pronouncement. If you don't
> feel confident in your PEP-writing skills, ask for help. (If you
> don't get any, you probably should take that as "the community says
> No".)
Well, my current PEP-writing-skills are kind of zero, but the problem
is that I don't know what to write there yet. PEP probably implies
that I want to change something, but my simplest patch [1] covers
most of use cases and changes nothing, except performance, and
should need no PEP.
The opposite to it is a unified container filling protocol. But it
has lots of options, and still heavily discussed.
>> Do you like having many broken tools?
>
> And please stop this. sum() is not broken, any more than a
> screwdriver is broken just because it is rather inefficient when used
> to pound in nails.
No, that would be the case if I was using sum for something that it's
not intended to do, e.g. instead of:
x = 60*70
I could try:
x = sum([60].__mul__(70))
That would work, but would be obviously inefficient, because sum() is
not intended to do multiplication.
`a + b + c + .. + z` is exactly what sum is supposed to do. But due
to some implementation-specific details it does that slowly for
some a...z types. It's not a technical problem, it's a political
(or personal ideology?) problem to allow sum being fast for types
that it was slow for last 10 years.
It's more like a drill, that is good for metal and bad for wood,
because it was equipped with metal drill bits, but not with wood
drill bits. It could be just fine for wood too, but its developer
believes, that his drill should not be used to make holes in wood.
Would you call such a drill "broken"? I would.
This bug was known for a long time, I just raised a question of what
would be the best way to fix that. Should we just equip it with a few
most common wood drill bits (e.g. lip&spur + spade)? Or should we put
a grinding stone in, so that anyone could make a drill bit himself?
Or maybe both?
--
[1]http://bugs.python.org/file30897/fastsum-special-tuplesandlists.patch
More information about the Python-ideas
mailing list