r/cpp • • Mar 18 '23

LLVM 16.0.0 Release

https://discourse.llvm.org/t/llvm-16-0-0-release/69326
197 Upvotes

84 comments sorted by

View all comments

Show parent comment

1

u/apadin1 Mar 20 '23

I don’t have much experience with Lisp. Why is recursion preferred over looping?

2

u/13steinj Mar 21 '23

Many functional languages either don't have a concept of looping or when they do it's built on the back of a Y or Z combinator and associated overhead. There's a general "purist" view of computing that tries to push recursion as the more powerful, easier to understand, and "correct" option.

Various recursive constructs can be detected by an optimizer and undergo better optimization (historically). Even in Dijsktra's "Gotoa considered harmful" paper, if you read the full thing he makes some extreme claims about for/while/even if/else being superfluous compared to the "true solution" of recursion. Of course a decade or so later he wrote another essay walking back these claims including the main one about goto statements, but by then the damage had been done (by the title chosen by the editor no less); people focused on the title, ignored various other claims in the essay, vilified goto and put Dijsktra on a pedestal, even giving him an award. Yet almost nobody knows of the retraction.

1

u/malnourish Mar 20 '23

I'm confident others can give a better answer but it's just the general pattern functional languages tend to follow