# Tail-call recursion

**URL:** <https://discourse.julialang.org/t/tail-call-recursion/87847>\
**Category:** Performance\
**Created:** [September 26, 2022, 10:09pm UTC](https://discourse.julialang.org/t/tail-call-recursion/87847 "2022-09-26T22:09:53Z")\
**Posts on this page:** 1\
**Showing post:** 37

<div class="post-metadata">

**Author:** ![gbellomia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbellomia/32/19443_2.png) [@gbellomia](https://discourse.julialang.org/u/gbellomia)\
**Post date:** [September 30, 2022, 8:07pm UTC](https://discourse.julialang.org/t/tail-call-recursion/87847/37 "2022-09-30T20:07:48Z")

</div>

Considered that the original comment I was replying to is

> [@Allocation and slow down when # of types involved increase (slower than C++ virtual methods)](https://discourse.julialang.org/t/allocation-and-slow-down-when-of-types-involved-increase-slower-than-c-virtual-methods/87656/38):
>
> Purely anecdotal information here, but one time I wrote a recursive function, and it was slow. I rewrote the function using a while loop, and it was fast. slight_smile So, perhaps your real issue here is using recursion.

Could this statement:

> [@gbellomia](#):
>
> I understand. Well, then (deep?) recursion is probably to be regarded a bad habit here, as loops are in python, R, Matlab…

be made reasonable by just replacing “(deep?)” with “tail”?

In other languages writing tail recursions in lieu of loops is perfectly fine, while here the loop should be preferred. Hence here it is a bad habit to choose recursion in the trivial cases where a loop could do fine. Right?

---

_[View the full topic](https://discourse.julialang.org/t/tail-call-recursion/87847)._
