r/programminghumor • • Sep 02 '26

Write sorry

Post image
696 Upvotes

96 comments sorted by

View all comments

4

u/Diocletian335 Sep 02 '26
void printSorry (int n, int v)
{
    if (n == v)
         return;

    printSorry(n+1, v);

    printf("%s\n", "sorry");
}

int main (void)
{
     printSorry(0, 100);
}

The thinking man's solution

9

u/gaymer_jerry Sep 02 '26

Why write a for loop when you can flood the stack with pointless function calls

5

u/Diocletian335 Sep 02 '26

Just using as much memory as the gods intended

1

u/MCWizardYT Sep 03 '26

Implement it with a trampoline function so that you get infinite recursion without blowing up the stack

2

u/realmauer01 Sep 02 '26

When our prof explained recursion to us he said, "okey i will only explain it this one time, and you please forget it immediatly, i will show you how to do it, so you dont need to think about it and it will just work, you will never want to use it though unless you need it and then you will understand it anyway."

Yeah something like that.

3

u/Diocletian335 Sep 02 '26

In all seriousness it's a useful little topic to learn from a theoretical perspective, but my thinking has always been if you are ever thinking 'surely I could just use a loop here' then you should be using a loop.

I've never used recursion in anything serious, at least not directly - some inbuilt methods may have used them.

2

u/realmauer01 Sep 03 '26

I have heard rendering stuff is done recursively.

2

u/geek-49 Sep 03 '26

recurses! refoiled! refoiled = foiled again

2

u/Vladislav20007 Sep 02 '26

the "just buy more memory" approach.

1

u/dmigowski Sep 02 '26

WTF is that slop?

3

u/Diocletian335 Sep 02 '26

Simple recursion

1

u/MCWizardYT Sep 03 '26

What, never seen a recursive function before?

1

u/dmigowski Sep 03 '26

I've never seen one that could be easier replaced with a simple for look, yeah. Why wasting 1200 bytes of stack here?

2

u/MCWizardYT Sep 04 '26

They wrote "the thinking man's solution", so it's 100% an unserious comment

1

u/Diocletian335 Sep 04 '26

This is, after all, a subreddit called programming humor lol

1

u/DiodeInc Sep 02 '26

Overthinking*

4

u/Diocletian335 Sep 02 '26

Yes this response was very serious