Answer the question
In order to leave comments, you need to log in
What is the difference between the concepts of function, procedure and method in programming?
Periodically I see all 3 definitions. Is it the same or something different, and which of the concepts is the most correct to use?
Answer the question
In order to leave comments, you need to log in
A function is a subroutine that performs some operation and returns a value.
A procedure is a subroutine that only performs operations, without returning a value.
A method is a function or procedure that belongs to a class or class instance.
D3lphi
A function is a subroutine that performs some operation and returns a value.
A procedure is a subroutine that only performs operations, without returning a value.
A method is a function or procedure that belongs to a class or class instance.
I'll take part too :)
in functional programming
in procedural
in the PLO
A procedure is a subroutine in a separate scope.
A function is a procedure that returns a value.
The method is either the first or the second.
Essentially, nothing.
In fact, little things.
For a method, the parameter is automatically the object of the class to which the method refers.
But no one bothers you to pass an object of the class explicitly as a parameter.
True, the class method will automatically have access to the internal protected fields of the class, which the function to which this class object is passed as a parameter will not have.
But it depends on the language. For Go, for example, if a function is defined in the same package, then there are no restrictions on access to internal non-public fields of structures.
Function vs Procedure - the result of the function can be directly assigned to a variable
on the other side, and with the procedure you can do the same, but a bit more complicated:
function(&b)
a = b
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question