Re:PHP: why GOTO instead of recursion?
by wtetzner on Tuesday September 23, 2014 @02:07PM
(#8356975)
> In the end, anything that can be done with tail recursion can be done in a loop which is way more readable then either using a GOTO or recursion.
The real value in TCO isn't a function recurring on itself, it's mutual recursion.
Re:PHP: why GOTO instead of recursion?
by crimsonalucard on Tuesday September 23, 2014 @06:32PM
(#8358762)
No, that is not the only case where it has value.
TRO is a mandatory optimization for functional languages where recursion is the only possible looping construct. Haskell, Clojure, Erlang and Lisps rely on it heavily.
Clojure another language that doesn't support tail recursion optimization (TRO) uses an ugly language construct called (recur) to mimic TRO which is essentially identical to a GOTO, so I don't see what the big deal is.
In the end, anything that can be done with tail recursion can be done in a loop which is way more readable then either using a GOTO or recursion. Tail recursion is only required for strict functional languages.