Recursion
Several people have asked me for reasons to use recursion:
bengalpedigrees.com is a project I volunteer server and programming on. It is pretty standard family tree record keeping and outputting of pedigrees...
why use recursion on this?
For one, you write one display function, then a pedigree of any depth can be called by the same function with a little math to determine which row you are currently displaying to place table cells properly.
I five generation pedigree has 2+4+8+16+32 for a total of 62 cells. Who the heck wants to hand code a page of that mess?
This means that the website is capable of outputting 1 row, or ALL the rows, based on a single function and parameter! A tiny amount of code that provides quite a bit of functionality and makes for easy to maintain.
So, anyone else have another example for a good use of recursion?
bengalpedigrees.com is a project I volunteer server and programming on. It is pretty standard family tree record keeping and outputting of pedigrees...
why use recursion on this?
For one, you write one display function, then a pedigree of any depth can be called by the same function with a little math to determine which row you are currently displaying to place table cells properly.
I five generation pedigree has 2+4+8+16+32 for a total of 62 cells. Who the heck wants to hand code a page of that mess?
This means that the website is capable of outputting 1 row, or ALL the rows, based on a single function and parameter! A tiny amount of code that provides quite a bit of functionality and makes for easy to maintain.
So, anyone else have another example for a good use of recursion?
Labels: family tree, geneology, recursion

0 Comments:
Post a Comment
<< Home