View previous topic :: View next topic |
Author |
Message |
predprey Master Cheater Reputation: 24
Joined: 08 Oct 2015 Posts: 486
|
Posted: Tue Nov 15, 2016 12:04 am Post subject: Tail call recursion in Java? |
|
|
is there a point for doing tail call recursion in java, on the assumption that you do not use any advanced features or something else similar such as scala?
for example if i were to write a tail call recursive function in C, it would run in a way such that unused stacks from previous calls are cleared. however, because there is no tail call optimization in JVM, doing so is pointless and may even incur more performance penalties than an iterative function or a non-tail recursive function due to the extra argument passing the result to the next call.
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Tue Nov 15, 2016 7:41 pm Post subject: |
|
|
If you think the code is easier to understand with recursion over a loop, then use it.
There's no point to avoid it, unless you have a specific fear of a stack overflow.
|
|
Back to top |
|
|
predprey Master Cheater Reputation: 24
Joined: 08 Oct 2015 Posts: 486
|
Posted: Tue Nov 15, 2016 9:31 pm Post subject: |
|
|
Zanzer wrote: | If you think the code is easier to understand with recursion over a loop, then use it.
There's no point to avoid it, unless you have a specific fear of a stack overflow. |
ok thanks. yea, i guess i would prefer iteration since it was able to calculate a larger input without overflow.
|
|
Back to top |
|
|
|