I'm looking at a function that that has several statements like this:
n = returnDifferentVersionOf(n);
I.e., the value of the same variable
n changes progressively several times during the course of a subroutine -- rather than a newly named variable being assigned at each change.
What is the generic name of this technique (if there is one)?
A more full example might be (in Ruby):
# reuse same var def cromulentize(str="") str = "wowza" if str.empty? str += " adios!" str = str * 3 str.gsub!('a', 'X') str = str[0..-3] str.upcase end
What is that technique called, as opposed to this one:
# uses diff vars def cromulentize(str="") non_empty_str = str.empty? ? "wowza" : str adios_str = non_empty_str += " adios!" multiplied_str = adios_str * 3 gsubbed_str = multiplied_str.gsub!('a', 'X') spliced_str = gsubbed_str[0..-3] upcased_str = spliced_str.upcase end
(Note that in Ruby the value of a method's last expression is the return value.)