Hard Light Productions Forums

Off-Topic Discussion => Programming => Topic started by: Polpolion on January 29, 2011, 03:59:52 pm

Title: tail recursion
Post by: Polpolion on January 29, 2011, 03:59:52 pm
seriously **** that ****

why would even want to bother

it's really hard to implement in most cases even if you understand non-tail recursion, and it's STILL WORSE THAN NORMAL ITERATION

don't even care that it might prevent offbyone errors; in the time it takes to implement a tail recursive function, you could probably write the function iteratively and check it over for offbyone errors

seriously, what gives
Title: Re: tail recursion
Post by: Iss Mneur on January 29, 2011, 05:12:01 pm
The nice thing about tail recursion is, if you have a compiler that is optimizing it will transform the code into a non recursive iterative call. Which means that you get the advantages of readability that you get with recursion and without the overhead of recursion.
Title: Re: tail recursion
Post by: Flipside on January 29, 2011, 05:17:31 pm
Used to use this a lot in Z80 because of limited CPU speed and stack-size, a jmp used less cycles than a jsr, so with iterative calls the savings used to be quite noticeable, and you didn't kill the stack.
Title: Re: tail recursion
Post by: Mongoose on January 29, 2011, 06:46:18 pm
I don't know about tail recursion specifically, but I do know that I found working with Scheme to be utter hell in the one class I took which used it, as the whole damn language is recursive.  Ugh.
Title: Re: tail recursion
Post by: Qent on January 29, 2011, 07:04:43 pm
Really? :( They told us up front, "If you can get recursion, you'll be fine; if not, you're screwed," and soon I grew to love it.