0

There is a lot of talk about loop-less (functional) programming languages, but I haven't heard of any modern recursive-less programming languages. I know COBOL doesn't (or didn't) support recursion and I imagine it's the same for FORTRAN (or at the very least they will have a weird behaviour), but are there any modern languages?

There are several reasons I am wondering about this...

  1. From what I understand there is no recursive algorithm for which no iterative implementation exists that is at least as performant (as you can simply "simulate" recursion iteratively, when managing the stack within the loop). So there is a) no performance gain and b) no capability gain from using recursion.
  2. Recursion can have worse performance than iteration for things like naiive, recursive implementations of fibonacci numbers. People like to point out that recursion can be just as fast when compilers are optimized and it comes to tail recursion, but from my understanding tail recursion algos always are trivial to convert to loops. So there is c) potential performance loss from recursion.
  3. Academics seem to have a thing for recursion, but then again most of them can't/don't really write any productive code. C++ (or object orientation in general) is the living proof how academic ideas can make their way into the business world/companies, while beeing mostly impractical. I wonder if recursion is only another example of this. (I know this is an opinionated topic, but the majority of accomplished software engineers I heard talk agree on this at least to some extent).
  4. I have written recursive algorithms in productive systems before, but I can't think of a time, when I really benefited from using recursion. Recursive algorithms d) may or may not provide code readability advantages in some cases. I am not sure about this...
  5. Most (all?) modern operating systems rely on specified call stack conventions. So if you want to call any external library from within your program, your programming language/compiler has to comply with the system's call stack convention. This makes it an easy step to adopt recursion for programming languages/compilers. However if you would create a recursion-less language you wouldn't need a call stack at all, which would have interesting effects in terms of memory management...

So I am not hating on recursion... I am just wondering if the recursion-less language experiment has been done in the recent past and what the results have been, as it seems like a practical experiment to me?

Wolf
  • 892
  • 2
  • 8
  • 22
  • 1
    There is a different between recursive/iterative process and recursive/iterative function/method. Eg. if you make an iterative function that does tree traversal with a stack it is still a recursive process. Also if you do tail recursion it is an iterative process even though the function is recursive. Functions and control flow except goto are not supported by any CPUs so everything is actually simulated and some features like vararg and tail recursion require particular calling conventions which your language might not support. – Sylwester Nov 15 '18 at 12:58
  • 1
    4. Inheritly recursive processes looks clearer when written as a recursive function/method. Usually performance and limitations make us replace 5 lines of code with 25. I tend to have the previous 5 lines as documentation so I do not understand how you think iterative functions always will be simpler to read. One should always write for readability since micro optimizations seldom works. – Sylwester Nov 15 '18 at 13:02
  • 5. read about basic design behind [Chicken Scheme](https://en.m.wikipedia.org/wiki/CHICKEN_%28Scheme_implementation%29#Design) and visit their official homepage https://www.call-cc.org - you seem to have a lot of misunderstandings about the topics in general. – Mulan Nov 15 '18 at 15:34
  • @Sylwester: Can you give me a 5 vs 25 lines example? I've seen a lot of examples like that, but the iterative version was always poorly written. I see what you mean when talking about the differentiation between processes and methods. Question would still stand though (in the meaning of language with no recursive methods). – Wolf Nov 15 '18 at 15:42
  • @user633183: That's terribly vague... could you be more precise about what general misunderstandings I have instead of pointing me to a totally unrelated and irrelevant programming language? – Wolf Nov 15 '18 at 15:43
  • @Wolf, how is it unrelated or irrelevant? It's a modern language that doesn't use a call stack. Yet it still supports recursion. Not sure why you think the two are married. – Mulan Nov 15 '18 at 18:52
  • @user633183: I asked "Are there any modern languages that don't support recursion?". You point to a language that _does_ use recursion. Unrelated to that point, the language uses the C Stack to an extrem extent... – Wolf Nov 15 '18 at 20:37

0 Answers0