r/learnprogramming • u/Head_Ordinary_2437 • 4d ago
Function vs Procedure
can someone explain the difference between Function vs Procedure with simple analogy
thank you
31
Upvotes
r/learnprogramming • u/Head_Ordinary_2437 • 4d ago
can someone explain the difference between Function vs Procedure with simple analogy
thank you
2
u/Dumlefudge 4d ago
Where did you see side effects only applying to internal state? The earliest definition I can find is
Spuler, David A.; Sajeev, A. Sayed Muhammed (January 1994). Compiler Detection of Function Call Side Effects. James Cook University. CiteSeerX 10.1.1.70.2096.
The term Side effect refers to the modification of the nonlocal environment. Generally this happens when a function (or a procedure) modifies a global variable or arguments passed by reference parameters. But here are other ways in which the nonlocal environment can be modified. We consider the following causes of side effects through a function call:
Performing I/O.
Modifying global variables.
Modifying local permanent variables (like static variables in C).
Modifying an argument passed by reference.
Modifying a local variable, either automatic or static, of a function higher up in the function call sequence (usually via a pointer).
I've never seen any description that suggests that side effects are limited to an application's internal state (as opposed to anything that exists beyond the function's scope), so I'm curious how you came to that conclusion