On Sun, 16 Mar 2014 02:11:43 +1100 Steven D'Aprano <steve@pearwood.info> wrote:
The possible reason given in the PEP is very weak and amounts to premature optimization:
I don't think it's premature optimization. Sometimes we do know ahead of time that a calculation done one way will be faster than doing it another way: you don't have to "try it and see" to realise that repeatedly adding strings in a for-loop can be O(N**2) versus O(N) for using str.join().
It's premature optimization because the PEP is proposing to enforce it at the language level. We didn't change *the language* so that "str +=" allows for O(N) repeated concatenation; instead we tell people that "".join() should be used for repeated concatenation. Why would our course of action be different for matrix multiplication? Regards Antoine.