Rough notes, on why tail recursion is not normally used in C#.
In Scala, tail recursion allows for recursive calls with a constant stack size. This is usually possible if the recursive call is the last part of that expression.
However, the C# language has no direct support for tail recursion.
Note: with 64bit release build, the JIT may detect tail recursion, and avoid stack growth.
In Scala, tail recursion allows for recursive calls with a constant stack size. This is usually possible if the recursive call is the last part of that expression.
However, the C# language has no direct support for tail recursion.
Note: with 64bit release build, the JIT may detect tail recursion, and avoid stack growth.
But not when debugging (so could have stack overflow, if debugging).
[to reserach] even with 64 but build, the tail recursion may not succeed, in some cases??
Other reasons why tail recursion is not typically used:
- not idiomatic C#
· Performance might be better without recursion (I think sometimes Resharper recommends to remove it)
· Tail recursion can sometimes be replaced by something else like Enumerable.Aggregate
Comments
Post a Comment