Program to backtrack function calls in source code?
Diez B. Roggisch
deets at nospam.web.de
Sat Sep 2 19:31:52 EDT 2006
forum at anton.e4ward.com schrieb:
> Hi,
>
> many mistakes in programming arise when one changes the code and
> forgets to adjustment somewhere where it is used. Is there a program
> that can extract all place in the source code where a variable is
> accessed or a function called?
> For example in the simplest case I want to change the name of a
> function everywhere in the source...
Others have given you answers that point to concrete, yet partial
solutions to your problem.
I just want to shed some light to the broader scope. There are limits to
what can be done in a dynamic language like python.
Lots of code (and very valuable one) in python lives from the fact that
e.g.
a = getattr(b, some_computed_name)
works. So, ultimately you will always encounter situations where a
simple name-replace won't catch all possible access/modification spots.
So, a language like e.g. java together with an ide like eclipse
shines in refactoring.
The fun fact is: having the compiler grok your code means close to
nothing - without proper testing, things can and will easily break.
The answer to this is: testing, as automated as possible. And funny
enough, that should (and will in most cases) catch whatever errors
resulted from that renaming.
So: use the mentioned tool, use pycheker and/or pylint to gain some
pre-running confidence in code changes.
But ultimately: test!
Diez
More information about the Python-list
mailing list