wiki:RefactoringSteps/RenameFunction

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

  1. The name label of the function is changed at every branch of the definition to the new one.
  1. In every static call to the function, the old function name is changed to the new one.
  1. Every implicit function expression is modified to contain the new function name instead of the old one.
  1. 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.
  1. 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.
Last modified 13 years ago Last modified on Feb 15, 2012, 12:05:08 AM