Self function

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Tue May 5 16:43:16 EDT 2009


wolfram.hinde...:
> It is easy to change all references of the function name, except for
> those in the function body itself? That needs some explantation.

I can answer this. If I have a recursive function, I may want to
create a similar function, so I copy and paste it, to later modify the
copied version. Then to change its name I usually don't use a search &
rename of its name into its block of code because it's usually
useless. In non-recursive functions the name of the function is stated
only once, at the top.

Recursive functions violate the DRY principle, that's the root of the
problem.

The auto(f) decorator shown later by Aaron Brady seems the best
solution found so far, it's so nice that it even seems practically
usable.

Bye,
bearophile



More information about the Python-list mailing list