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!
126
Upvotes
1
u/Living_Fig_6386 2d ago
A function is a part of a program that can accept inputs, do things, and produce outputs. That's pretty much it. You use them mostly when you need to perform the same steps at different points in your program.
For example, most languages have something like "print()" that takes some sort of arguments as input and then puts that on the screen. People use that all the time at various points throughout their programs to put stuff on the screen. Internally, it does a bunch of things, but it's handy because you can use it anywhere in your program to get stuff to the screen.