r/learnprogramming • • Apr 05 '22

Name one programming/comp sci concept you never understood and if you understand it, try to explain it to them

Name a programming concept such as virtual functions, pointers, certain algorithms, etc that you always had a hard time understanding and why.

Someone else who reads yours and does understand it, try to explain it to them to help them learn

1.6k Upvotes

738 comments sorted by

View all comments

Show parent comments

101

u/Emerald-Hedgehog Apr 05 '22 edited Apr 06 '22

Alright. Imagine you got a steak and you wanna cook it well done. It's needs to be cooked 5 minutes for that.

Function CookSteak(🥩)
{
   🥩.CookedMinutes += 1

   If (!🥩.IsWellDone()) { return CookSteak(🥩) }
   else { return 🥩 }
}

Does this help?

49

u/KrafDinner Apr 05 '22

I'm not sure if it helped the asker or not, but it's a fantastic explanation... and steak... mmmm

36

u/WarWizard Apr 05 '22

Why not just call this function BurnSteak() or MakeSteakInedible()

:D

14

u/_Personage Apr 05 '22

function cookShoeLeather()

Yeah, that was the last time I made any sort of meat for the person who called my meat tacos that :(

2

u/ballbeamboy2 Apr 05 '22

>!🥩.isWellDone()

Could be understood as !CookedMinutes == 5 which mean if the steak's cookeMminute is not equal to 5 then continue cooking, and once cookedMinutes is 5, return the steak and recursion will stop calling because. the exit condion is when cookedMinutes is 5

1

u/Emerald-Hedgehog Apr 06 '22

Yes, exactly, your explanation is on point! Should've written it as you described to keep it even easier to digest. :)

2

u/OfJahaerys Apr 05 '22

Also, if you speak another language, most European languages have something called a reflexive verb. It is the same thing as recursion just as a string ;)

"Je m'appele" in French is an example. It folds back on itself.

2

u/Saturnzadeh11 Apr 06 '22

Now I’m wondering if I’m doing fine with recursion when so many around me are not because of all the Spanish I took 😮

1

u/OfJahaerys Apr 06 '22

It is definitely the reason I don't have trouble with it.

1

u/MyBrainReallyHurts Apr 05 '22

Yes, and now I'm hungry.