When working with recursive functions, the way to effectively express what the function performs is to consider it as a mathematical function and simplify the application of the function. Although this does not really tell you about the internal state of the function (in this case, the value is temp ), it gives you a very good way to describe this function.
For factorial, we can determine the fact:
fact(x) = 1 when x <= 1 fact(x) = x * fact(x - 1) otherwise
Now that you want to express how it works, you select a small starting number (say 6) and ...
fact(6) = 6 * fact(5) = 6 * 5 * fact(4) = 6 * 5 * 4 * fact(3)
etc.
Thus, what you do is an analysis of the structure of the function, not its implementation. Now for debugging purposes this is not very useful (at least not in a non-functional language). But this is great for comments, documentation, and communication.
source share