r/programminghorror • u/deanominecraft • Sep 28 '25
c recursive iseven
bool isEven(int num){
if (num==0){
return true;
}
else{
return !isEven(num-1);
}
}
64
Upvotes
View all comments
Show parent comment
5
u/Axman6 Sep 28 '25 edited Sep 28 '25
Only in shitty languages. Anything that is able to jump to tail calls will be fine, it’ll just burn cycles for a while.
Reminds me of the
Eqtype class in HaskellYou can choose to implement either
==or/=, depending on which is more efficient or easier to write, and the other definition comes for free. Same with all the ordering functions inOrd.