Language for the ages

Sridhar Ayengar ploopster at gmail.com
Thu Oct 20 15:03:14 CDT 2005


Chuck Guzis wrote:

>>Recursion makes a lot of sorting/searching algorithms much cleaner too.
>>
>>Plus, IMHO the recursive factorial (x!) algorithm looks a lot less 
>>complicated.
> 
> Not to offend the purists, but...
> 
>>From an efficiency standpoint, recursion is seldom the best solution in the
> real world as opposed to an iterative solution.  With recursion, you're
> using the CALL mechanism to provide a new data frame and arguments for each
> iteration.  With a simple loop, an indexed array can provide the same
> functionality at much lower overhead--and be more predictable as to the
> amount of storage required.
> 
> Perhaps there are architectures where this is not true, but in my
> production codes, I've found it more efficient to climb directory trees
> with a simple loop--with an index limit check, rather than, say, throwing
> an exception for stack overflow in the case of recursion.

But I wasn't talking about efficiency, I was talking about cleanliness. 
  Hand-optimized iterative assembler is some of the most efficient code 
I can think of, but a lot of the time, it tends not to be very clean.

The right tool for the right job, and all.

Peace...  Sridhar


More information about the cctalk mailing list