I just came across a fun little blog post about benchmarking the new version of Ruby by doing a Fibonacci sequence.  I hadn't thought about playing with Fibonacci sequences in a long time and since several others did it already I didn't really try.  I just ran one of the CF code examples someone posted on my MacBook Pro.  I blinked and missed the execution of it. Meh, fast enough.  

Like I said I hadn't thought about Fibonacci or other such algorithms in a long time.  At least not much since college when we all learned such things along with various sorting algorithms (who can forget the bubble sort?).  Why did we learn those when today we just write something like sort(blah) and never think about how it gets done.  I remember working on analyzing sorting algorithms to see which was the fastest and most memory efficient.  Memory efficient?  That is a novel concept these days.

However, a while back I did a recursion experiment in ColdFusion by doing a Factorial function which in college is one of the classic programming examples used to teach recursion.

I'm not even sure where you would use recursion these days, except in programming classes.  I have not run across the need for it in ages, but for some reason I was compelled to try this little experiment.

Is there really a need for recursion these days, or are we overlooking a power tool?

view plain print about
1<cffunction name="factorial" access="public" returntype="numeric" output="yes">
2    <cfargument name="end_value" required="Yes" type="numeric">
3    <cfif end_value lte 1>
4        <cfreturn 1>
5    <cfelse>
6        Calling myself with #arguments.end_value-1#<br>
7        <cfreturn end_value * factorial(arguments.end_value-1)>
8    </cfif>
9</cffunction>
10<cfoutput>#factorial(100)#</cfoutput>