This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Kwpolska
Recipients Kwpolska, docs@python, rhettinger
Date 2017-03-05.16:32:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1488731524.9.0.615939918768.issue29724@psf.upfronthosting.co.za>
In-reply-to
Content
The itertools recipes list [0] ends with the following dubious advice:

> Note, many of the above recipes can be optimized by replacing global lookups with local variables defined as default values. For example, the dotproduct recipe can be written as:
>
> def dotproduct(vec1, vec2, sum=sum, map=map, mul=operator.mul):
>     return sum(map(mul, vec1, vec2))

This is presented in the document without any explanation. It may confuse beginners into always doing it in their code (as evidenced in #python today), leading to unreadable code and function signatures. There is also no proof of there being a significant speed difference by using this “trick”. In my opinion, this should not be part of the documentation, or should provide proof that it can provide a real, noticeable speedup and is not premature optimization.

(Added in [1] by Raymond Hettinger — added to nosy list)

[0]: https://docs.python.org/3/library/itertools.html#itertools-recipes
[1]: https://github.com/python/cpython/commit/fc91aa28fd8dad5280fd4d3a4747b5e08ee37ac0
History
Date User Action Args
2017-03-05 16:32:04Kwpolskasetrecipients: + Kwpolska, rhettinger, docs@python
2017-03-05 16:32:04Kwpolskasetmessageid: <1488731524.9.0.615939918768.issue29724@psf.upfronthosting.co.za>
2017-03-05 16:32:04Kwpolskalinkissue29724 messages
2017-03-05 16:32:04Kwpolskacreate