Subj : Re: Are recursive functions ever needed? To : comp.programming From : Randy Howard Date : Sat Oct 01 2005 01:54 pm John wrote (in article ): > "Tatu Portin" wrote in message > news:S6v%e.208$nZ1.35@read3.inet.fi... >> Are recursive functions ever needed, i.e. cannot you just replace them >> with iterative clauses? >> >> Example: >> >> b = func (func (func (a))) >> >> compared to: >> >> b = a; >> for (i = 0; i < 3; i++) >> { >> b = func (b); >> } > > Hi Tatu, > > I suppose you can do that when you know the depth of the calls while your > programming. But what if you are building something where you don't know > the node depth? Which is almost always. > I have seen loops when a recursive function is called for. But, in my > experience, they quickly become convoluted where as the recursion is > simplistic. When ever I've seen it done, it has been a bug filled mess and > a maintenance nightmare. Which balances out nicely with all the bugs that show up as a result of unbounded recursion. :-) > I do understand some people just can't get their head around it. I know a > programmer who is highly regarded by his peers and clients .. but just > doesn't get it ... I thought he was joking when he first told me. Try this on him. Knock, knock. Who's there? Recursion. Recursion who? Knock, Knock. .... -- Randy Howard (2reply remove FOOBAR) .