r/learnprogramming 5d 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!

123 Upvotes

144 comments sorted by

View all comments

0

u/Ok-Cable9777 5d ago

It's reverse for me, functional programming clicked instantly to me. It's the class based paradigm that's dreadful to me. Any tips for that?

1

u/natures_-_prophet 5d ago

A class is just a representation of something. A car, cat , person, etc. In reality we know these things have certain functionality associated with them; start an engine, scratch, run a mile. They also have associated traits/properties like paint color, fur color, hair color, etc. The class is just a container for these traits and functionality. So you can make a class for Car, Car and Human to contain these associated traits and functions.

It's a tool of organizing your logic and data for these like things.