On Thu, 12 Mar 2020 at 21:10, Dominik Vilsmeier
<[email protected]> wrote:
If I wanted to split the computation over multiple lines and yet have it
optimized I would just reuse the same (target) name instead of creating
a temporary one and then discarding it in the next step:

      a = b * c
      a += d
This is __exactly__ the point: the numpy patch author said that, with
that patch, this is done automatically __without__ the need to split
the code.

The point is that sometimes you _do_ want to split your code over
multiple lines for the sake of clarity.
Using meaningful names for each of the steps seems intuitive but since
this leads to temporary objects it can hurt performance. I had the
impression that the original example was addressing exactly this case.


I think this is not entirely a bad idea (the idea, not the
implementation). The problem is this can be safely done only for
immutables. Furthermore this will speed up things only if the object
is large. The splitted code will be slower for any other case.

Maybe this can be implemented for tuples too, the only other immutable
in Python, apart str, that can be large. But I rarely see operations
with tuples that needed to be optimized.
`int` can be large too; for example `1024 ** 1024 ** 1024`.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/PLVRHDOJFYRTBXULZ4VDIFKHNPZC4KBA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to