What are the method, function, and procedure definitions?


I've always thought the definitions were these, but it seems like I'm wrong:

  • Functions: Every procedure that returns something

  • Methods: Any procedure that returns nothing

I wonder if these settings are correct, and if they are not, or if they are partially, in what contexts these variations would occur.

Obviously, I'm only interested in definitions that exist in the programming world ... at most going a little bit to the side of mathematics.

asked by anonymous 04.04.2014 / 21:41

4 answers

  • Procedure : Part of a program or class that does not return a value (from the Delphi / Pascal definition). In Visual Basic / VB.NET, it is also known as Subroutine (Subroutine, or simply Sub );
  • Function : Part of a program or class that returns a value (from the Delphi / Pascal / Visual Basic / Visual Basic .NET definition);
  • Method : Procedure or function belonging to a class (various programming languages define this, for example, , c # , , etc. ).

There is a question in the Programmers where this is widely debated, but the consensual is that.

04.04.2014 / 22:09

definition of method in English wikipedia says it's a procedure associated with an object, and can also be called a member function . Static methods would be those associated with a class.

Often the terms function , method , procedure , routine and subroutine > are used interchangeably to refer to the same thing, but there are some nuances.

I see no difference between procedure , routine and subroutine . They are synonyms of a program-specific instruction sequence, which can be invoked from other locations.

A function refers to something that returns a value, analogous to mathematics. It would be a set of statements that returns a value at the end. A function is a procedure, but with this detail of the return more.

A method can be a procedure or function , but associated with an object or class. So it can be called a "member function".

Practical examples

Procedures are used in languages such as SQL (T-SQL, PL / SQL, etc.) for routines that do not return value. Already functions are used for routines that return values. The same goes for Visual Basic.

Several languages that have first class functions, such as Javascript, have the function declaration with the reserved word function .

Object-oriented languages such as Java or C # always use the term method to refer to the procedures associated with classes.

In PHP, which is object-oriented and functional, the term function is used to refer to routines called directly in code, while the term method is reserved for the object-oriented part, which is nothing but functions within classes. PHP makes no difference between function that returns value or not.


Although I did not cite strong references from authors, I think the content of Wikipedia is consistent and the definitions make sense in general on all platforms I know.

04.04.2014 / 22:33

In order to conceptualize function, method and procedure, one must take into account the basis of programming that is the study of the algorithm:

In algorithm functions, also known as subroutines, always return some value. One of the great benefits is that you do not need to copy the code every time you need to perform that operation, as well as making code reading more intuitive. For example: You can create a function to calculate the square root and return a value. Whenever you need it, the same function will be called and you will not have to re-create the calculation multiple times in your code. You create it only once.

Procedures differ from functions only because they do not return results. Example: To read the value entered by a user we use the READ procedure and to display text on the screen we use the WRITE procedure. The first just saves the text and the second just prints on the screen, not returning values to be used.

And the method, is it a function or a procedure?

A method can be either a function or a procedure. We call a method function or procedure in object-oriented programming when they are associated with an object or a class. Method is the name given to functions and procedures in object-oriented languages, only for a conceptual question of these languages. Basically, they end up being the same thing.

08.10.2016 / 01:14


A class is the responsibility. In software engineering, when you take responsibility for a class in a class diagram, those are the methods.


It's a piece of code (subroutine) with no return value.


It's a piece of code (subroutine) with return value.

08.10.2016 / 01:22