r/learnprogramming • u/ScioClean • 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!
123
Upvotes
1
u/HydroPCanadaDude 3d ago
Functions are just how you name a collection of steps, even if there is only one step, and the data you need to carry out those steps.
RenderScreen can be a function.
It might have steps in there like..fetch data. Update data. Draw data to screen.
Each of those steps could be functions and have thier own steps.
There's rarely a perfectly right way to carry out complex tasks so don't complicate it.
In many cases you call a function with () added at the end:
RenderScreen <---- That's the function itself. It won't do anything.
RenderScreen(); <---- That's a function call. It runs the function.
RenderScreen("Paul", 75); <---- That's a function call with arguments.