Difference between procedure and function


Hi all,

I just wanted to check if I have this correct…

The difference between a function and procedure in both Python and mel is that a function has a return value but a procedure does not return anything. Also, in mel both of them begin with the word proc(which is a little confusing!)



Indeed thats the definition but in Python a procedure always returns something. If you don’t return something explicitly, None is returned. So all procedures in Python are functions :wink:


In mel, there is not difference between a procedure and a function. Its possible to return a value, but you are not forced to do that. But generally, a procedure must begin with ‘proc’ or ‘global proc’.

In mel, there is a difference between ‘command style’ and ‘function style’.
So, you can write:

string $sel[] = `ls -sl`;

or you can write:

string $sel[] = ls( "-sl" );


You can throw the 2 terms around pretty interchangeably, are just cutting hairs if your trying to break out a separate meaning for function and procedure.

the proc vs def thing is just different languages define functions in different ways.

In the future if you get into the OOP side of python you will also see the term method, which is also just a function, that is also defined with the “def” keyword. It just means it is a function that is a member of a class or object.


Hmmm… I thought in mel there is a difference:


proc doSomething(int $value)


proc int doSomething(int $value)
	return 123;

So you can’t return a value from inside a procedure or am I completly wrong?


ya because you didn’t define a return type, i was just saying they use hte same keyword and work the same aside from that. Which would seem pretty obvious you cant return if you didn’t define the return.


In the case of MEL and Python the difference is in semantics if you discuss it with someone, not in functionality, nor in syntax. Read: useless.

In computer science there IS such a distinction between function and procedure, which are two specialization of subroutines, which are a subset of general routines, and that distinction is whether they have a return or not (a function does, as it takes from its mathematical counter part, a procedure doesn’t, as it takes from its systems counter part).

Going through various languages you can see this reflected in their syntax and dictionary, or not.

Beside this largely useless bit of historcial knowledge, you are confusing yourself. In Python and in MEL there is no such distinction, and one or the other is, under the hood, exactly the same. On top of that, they make no semantic distinction either.
C++ is the same, so is C, and so are the majority of modern mass diffused languages.

You have to go back a fair chunk in time (Pascal and its spawn), or into niche functional programming languages (where the mathematic affinity makes it a relatively important distinction) for it to be an actual distinction you have to worry about.

In general computing and in the side of it you deal with in CGI you don’t care, you work to a much more generalized model, and you shouldn’t let it confuse you. They are all just routines called one or the other purely on the language’s authorship original whims, and whether they behave as one or the other is left to the user (specifying a return or not in MEL, masking it in Python, declaring a void function in C++ and so on).