Martin Gregorie said:
but it was a long time ago and I don't really remember. I'm pretty
From a pure factual perspective, there is no need to
explicitly teach recursion, once it has been taught that
- A method might invoke a method
- Each method invocation has a fresh compound
of local variables (aka »activation record«
or »incarnation« or »block instance« or
»instance« of the method)¹
(The second assumptions fails for certain languages, such as
old FORTRAN or BASIC. So, when one has first learned such an
old language and now learns Java, he needs to learn the second
fact about the local variables.)
The other perspective is, of course, that pupils will not
always be able to immediatly see all relevant implications of
these two facts, so recursion needs to be taught. Moreover, it
also helps to clarify and test the understanding of both of
these facts.
When I teach recursion, sometimes - as an intermediate
step - I introduce redundant functions first.
For example, a method, that can print 0, 1, 2, or 3 asterisks:
public static void print( final int number )
{ if( number > 0 )
{ java.lang.System.out.print( '*' );
print1( number - 1 ); }}
public static void print1( final int number )
{ if( number > 0 )
{ java.lang.System.out.print( '*' );
print2( number - 1 ); }}
public static void print2( final int number )
{ if( number > 0 )java.lang.System.out.print( '*' ); }
These are kinds of »static incarnations« - each
incarnation has method declaration in the source code.
From there, the step towards recursion is the observation
that the three function declarations are nearly identical
and, thus, can be merged as one.
1) Objects, historically, were generalisations of
method incarnations - namely, class declarations
were generalisations of procedure declarations:
»A procedure which is capable of giving rise to block
instances which survive its call will be known as a class;
and the instances will be known as objects of that class.«
»3.« in »III. Hierachical Program Structures«
Ole-Johan Dahl und C. A. R. Hoare, Seite »179« in
http://portal.acm.org/ft_gateway.cfm?id=1243383&type=pdf