guys, tail recursion is a so tasty optimization. W...
# getting-started
e
guys, tail recursion is a so tasty optimization. Why it’s not turned on by default in kotlin? Why compiler can’t itself to recognize all cases for tail recursions in our code, and do appropirate stuff? Why do we need manually tolk to compiler via special keyword? (like “tailrec”). Tail recursion seems to be an ordinary optimization, like constant folding… and kotlin (and other langs) have no special keywords to turn constant folding optmiziations on!
d
evkaky: Because a method that relies on tail-recursion will most likely break (or tank in performance) if the tail-recursion-optimization fails, because you changed a bit of the code. It is much better to make it explicit ("I expect this to be optimized") and then get a note when it cannot be optimized than to dig around in the bytecode to figure out if the compiler did what you want.
👍 4
e
sounds reasonable, thank you