On Thu, May 27, 2021 at 7:24 PM Chris Angelico <ros...@gmail.com> wrote:

>   But `len_ = len` does work.  However, that doesn't change the
> > calculus at all for me.  My point wasn't about using the exact same
> > variable name.  It's that ANY ability to create a local variable that is
> > a fast-lookup shortcut for a global one is enough.
>


> The change of variable name is significant, though. It means that this
> is no longer a minor change to the function's header; in order to use
> this optimization, you have to replace every use of the name "len"
> with "len_" (or "_len").


sure. but this is only worth doing if you are using that name in a tight
loop somewhere -- so you only need the special name in one or two places,
and I've always put that hack right next to that loop anyway.

if you are calling, e.g. len() in hundreds of separate places in one
function -- you've got a much larger problem.

-CHB

-- 
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/UHBNGLJIK5WZLZXGG3TRJKINAUYGXCWX/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to