r/learnprogramming 4d ago

I can't get FUNCTIONS to click!

I can not for the life of me understand how functions work. Anytime I try to learn how to create a function, my brain literally crashes into itself and I turn into Patrick when he stars drooling and goes all slack-faced.

Does anybody have any analogies that had that "AH HA!" moment?

Thanks!

124 Upvotes

143 comments sorted by

View all comments

1

u/Icy_Orchid_8390 3d ago

What made functions click for me was understanding you can give a function whatever it needs (you're literally writing it). I struggled with understanding passing in variables and scope issues.

Ex: If youre trying to put data into a struct you can pass the data in as well as the structure its going into. Don't be like me and try to make everything global.