Self function
Terry Reedy
tjreedy at udel.edu
Thu May 7 00:33:26 EDT 2009
Steven D'Aprano wrote:
I am writing a book (with Python package) on algorithms that has *lots*
of recursive functions. I have also discovered that changing names can
be a pain. So in the text, (but not code) I have tried the equivalent of
# real_name
def f(params):
... f(args)
(This also keeps lines short enough for side-by-side versions, when I
want to do that.)
> But regardless, everyone is missing the most important point: why are you
> copying and pasting code in the first place?
In my case, I will be discussing variations of algorithms. Copy and
edit minimizes fatigue and errors and maximizes parallelism.
That is surely very close to
> the top of the list of Worst Ever Anti-Patterns, and it should be avoided
> whenever possible.
Not if the alternative is re-typing ;-).
> In Python, we can avoid much copy-and-paste coding with decorators.
But not when the variation is in the guts of the code.
> because recursive functions in Python don't actually call themselves,
> they call whatever happens to be bound to their name at runtime.
I have mentioned that. Also, apparently non-recursive functions can
become recursive after the fact by being bound to another name used in
the function.
tjr
More information about the Python-list
mailing list