New submission from Chris Warrick: 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/fc91aa28fd8dad5280fd4d3a4747b5e08ee... ---------- assignee: docs@python components: Documentation messages: 289020 nosy: Kwpolska, docs@python, rhettinger priority: normal severity: normal status: open title: Itertools docs propose a harmful “speedup” without any explanation versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue29724> _______________________________________