Message289020
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 |
|
Date |
User |
Action |
Args |
2017-03-05 16:32:04 | Kwpolska | set | recipients:
+ Kwpolska, rhettinger, docs@python |
2017-03-05 16:32:04 | Kwpolska | set | messageid: <1488731524.9.0.615939918768.issue29724@psf.upfronthosting.co.za> |
2017-03-05 16:32:04 | Kwpolska | link | issue29724 messages |
2017-03-05 16:32:04 | Kwpolska | create | |
|