[Python-ideas] Fast sum() for non-numbers - why so much worries?
David Mertz
mertz at gnosis.cx
Sat Jul 13 00:01:50 CEST 2013
On Fri, Jul 12, 2013 at 2:40 PM, Joshua Landau <joshua at landau.ws> wrote:
> On 12 July 2013 22:33, David Mertz <mertz at gnosis.cx> wrote:
>
>> 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.
>>
>
> Really? As bad as a frame-hack?
> I'm not arguing, just surprised.
>
I think so. I'm not trying to hang any big moral on the exact ranking of
"bad habits" in Python.
But ._getframe() has the virtue that it sometimes lets you do something
that you simply *cannot* do using non-hacky code. These things should be
nicely hidden away in modules where average users don't have to think about
the magic, but for their arcane maintainers, they can be useful. Maybe
throw in some metaclass programming hacks in the same category here.
In contrast, there is simply *nothing* one can do by sum()'ing sequences
that you can't do with other (more) straightforward code, either
itertools.chain() or a small explicit loop.
--
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/0a3f32c6/attachment.html>
More information about the Python-ideas
mailing list