I wince every time I see naive recursive fibonacci as a code example. It is a major turnoff because it hints at a lack of experience with tail call optimization, which I consider a must have for a serious language.
Perhaps calling it an “optimization” is misleading. Certainly it makes code faster, but more importantly it’s syntax sugar to translate recursion into loops.
(To be fair, if you are programming functionally, it is essential. But to flat-out state that a language that doesn't support isn't "serious" is a bit rude, at best.)
If I put out a language that crashed after 1000 iterations of a loop, I'd welcome the rudeness.
If every iteration of a while-loop cost you a whole stack frame, then I'd be very rude about that language.
This works, btw:
#include <stdio.h>
long calc_sum(int n, long acc) {
return n == 0
? acc
: calc_sum(n-1, acc+n);
}
int main(void) {
int iters = 2000000;
printf("Sum 1...%d = %ld\n", iters, calc_sum(iters, 0));
return 0;
}Well, sure, but real programmers know how to do while loops without invoking a function call.
Yes, you can stare into the abyss, but it's staring right back"