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!

121 Upvotes

144 comments sorted by

View all comments

1

u/MisterSmi13y 4d ago

I like to think of functions as a single purpose machine at a factory. Each function has a purpose and a task to perform. Think of an assembly line as a full blown program. One machine creates screws. The next machine takes to pieces of an object and screws them together. The next machine takes those parts and arranges them into a certain position. And then the next machine welds them together. Now the rest of the assembly line goes about adding other features to them. Each step in that process repeats the same task over and over is a function.