convenience
Barry Scott
barry at barrys-emacs.org
Wed Mar 23 05:09:21 EDT 2022
> On 22 Mar 2022, at 18:00, Avi Gross via Python-list <python-list at python.org> wrote:
>
> An earlier post talked about a method they used for "convenience" in a way
> they apparently did not understand and many of us educated them, hopefully.
>
> That made me wonder of teh impact on our code when we use various forms
> of convenience. Is it convenient for us as programmers, other potential readers,
> or a compiler or interpreter?
Using aliases can impose a cost for maintenance. It adds a burden on the reader
to figure what an alias really refers to.
I encountered this:
from time import time as now.
The use of now() was just confusing to maintainers.
I avoid the convenience path as it often makes maintenance harder.
>
> The example used was something like:
>
> varname = objectname.varname
>
> The above clearly requires an existing object. But there is no reason it
> has to be the same name. Consider the somewhat related idea used
> almost always in code:
>
> import numpy as np
>
> Both cases make a sort of pointer variable and are a tad shorter to write.
>
> But what impact does it have on interpreters and compilers?
On the positive side aliases are very useful to improve the speed of
hot-path code.
read = this.that.the_other.read
while condition:
buf = read()
...
As with all optimisations only do this if you can justify it with benchmark results.
Barry
More information about the Python-list
mailing list