Home Segments Index Top Previous Next

332: Sidetrip

You have seen two recursive definitions: one for powerOfTwo and one for rabbits. Many mathematically oriented programmers prefer such recursive definitions to iterative definitions, when both are possible, believing that there is inherent elegance in defining a method partly in terms of itself.

Other, practically oriented programmers dislike recursive definitions for one or both of two reasons: first, the recursive approach usually produces much slower programs, because each send operation takes time; and second, the recursive approach may have problems with large arguments, because the number of send operations in a recursive chain of sends is usually limited to a few hundred. Recursion aficionados counter by creating compilers that handle certain recursive methods in sophisticated ways that avoid such limits.