functionterminologyprocedure

What is the difference between a "function" and a "procedure"?


Generally speaking, we all hear about the functions or procedures in programming languages. However, I just found out that I use these terms almost interchangeably (which is probably very wrong).

So, my question is:

What is the difference in terms of their functionality, their purpose and use?

An example would be appreciated.


Solution

  • A function returns a value and a procedure just executes commands.

    The name function comes from math. It is used to calculate a value based on input.

    A procedure is a set of commands which can be executed in order.

    In most programming languages, even functions can have a set of commands. Hence the difference is only returning a value.

    But if you like to keep a function clean, (just look at functional languages), you need to make sure a function does not have a side effect.