[Python-Dev] [slighly OT] Native speakers and hurting brains (original) (raw)

Boris Borcic bborcic at gmail.com
Tue Jul 11 14:43:52 CEST 2006


Greg Ewing wrote:

Boris Borcic wrote:

I believe that in this case native linguistic intuition made the decision... The reason has nothing to do with language. Guido didn't want sum() to become an attractive nuisance by appearing to be an obvious way of joining a list of strings, while actually being a very inefficient way of doing that.

sum() is exactly an attractive nuisance by appearing to be an obvious way of chaining strings in a list (without actually being one).

Considerable effort was put into trying to make sum() smart enough to detect when you were using it on a list of strings and do "".join behind the scenes, but Guido decided in the end that it wasn't worth the trouble, given that he only ever intended sum() to be used on numbers in the first place.

That's not quite conform to the record. According to py-dev archives it happened on April 2003 with a thread "Fwd: summing a bunch of numbers (or "whatevers")" initiated by Alex Martelli where he actually proposed a working implementation of sum() in C, that did short-circuit the case of strings to ''.join. That was Sat 19th of April.

Debate ensued, and by late Sunday 20th around 11PM;, the honorable author of the Zen of Python had killed that use case for sum() with "sum(sequence_of_strings) hurts my brain". (Hello Tim, so what about < sqrt(':(') > ?)

Guido's first intervention in the thread was the next morning, and the two very first lines of his intervention where :

"OK, let me summarize and pronounce.

sum(sequence_of_strings) is out...."

I admit that there is a step of arguable interpretation from these recorded facts to my diagnostic, but the latter is compatible with the facts. Your version otoh looks more robust in the role of eg creation myth.

Best Regards, Boris Borcic

"assert 304 in 340343, P424D15E_M15M47CH"



More information about the Python-Dev mailing list