Version 1 (modified by manualwiki, 13 years ago) (diff) |
---|
Rename function
The name is an important property of a function. While its actual value does not influence the semantics of the program, it is a key point in the readability of the code, and because Erlang programs mainly consist of functions, their names play an often underestimated role in software development and support. It is worth the effort to try to choose them well, and to correct misleading names even when they are user throughout the code. This transformation helps in the latter case:
doit(P) -> P ! {msg, start}. start(Lst) -> lists:forall( fun doit/1, Lst).
Result:
send_start(P) -> P ! {msg, start}. start(Lst) -> lists:forall( fun send_start/1, Lst).
Side conditions
- There must be no function with the given name and the same arity as the function to be renamed among the functions in the module, the functions imported in the module, and the auto-imported BIFs.
- There must be no function with the given name and the same arity as the function to be renamed among the local and imported functions in the modules that import the function to be renamed.
- If the user does not specify a function to be renamed or the specified function does not exist, the transformation starts an interaction to ask the user to specify one. The user has to select a function from a radio group.
Transformation steps and compensations
- The name label of the function is changed at every branch of the definition to the new one.
- In every static call to the function, the old function name is changed to the new one.
- Every implicit function expression is modified to contain the new function name instead of the old one.
- If the function is exported from the module, the old name is removed from the export list and the new name is put in it.
- If the function is imported in an other module, the import list is changed in that module to contain the new name instead of the old one.