From Newsgroup: comp.lang.python
ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
totally implement anything in an imperative or functional style.
In functional programming, you don't redefine names. So,
|let i := 7
is still kosher with functional programming, while
|let i := 7
|let i := 8
is a no-go. Why am I bringing this up?
If you redefine a name in a Python module (since around 2022), like,
|i = 7
. . .
|i = 8
, you're putting the kibosh on a certain optimization for name lookup
and your program's going to drag. This means that sprinkling in a little
functional programming mojo can make your Python programs zip along!
This was laid out by Kevin Modzelewski in a talk back in 2022.
He dropped these nuggets for Python programs (for CPython, I take it)
that don't cramp modern optimizations:
- Don't reassign global variables.
- All objects of a class should have the same attributes
(names, not values; i.e., "obj.dict.keys()" shouldn't
be different between objects of the same class).
- Set the same attributes in the same order for all objects
of a class.
- Use slots.
- Don't change attributes of classes of objects.
- Don't bother trying to optimize attribute lookup for
method calls outside of loops anymore.
(Don't try to "cache" methods in variables.)
The optimizer will take care of this today better
than you could ever do.
What else puts the brakes on a program is using module "getattr"
methods and tracing or profiling.
--- Synchronet 3.20a-Linux NewsLink 1.114