zero said:
As an aside, I
personally think the distinction between function and procedure is
nonsensical in languages like C/C++ & Java. Functions that don't return
anything are just that - functions with a void return type. IMO the
different names stem from different languages (eg pascal uses procedures),
not from a real functional difference.
The different names comes from Math. Math defines a function as a
mapping between two sets, called the "domain" and "range". For every element
in its domain (the input), it must map to exactly one element in the range
(the output). Thus, technically, something which "returns" two values is not
considered a function (though it could return a single element, where that
element it itself a set or list or something with cardinality greater than
one; this is like returning a Vector<String> in Java -- you're not returning
multiple strings; you're returning a single vector of strings).
Functions, according to the mathematical definition, should have not
side effects. A function shouldn't "print to the console" or anything like
that; it should just, given an input, return an output.
Also note that functions shouldn't have state, nor return something
different given the same input.
"Sine" and "Cosine" are considered to be functions in Math.
A procedure, on the other hand, comes from the English term, meaning a
way of doing something. There is nothing implying that a value should be
returned or anything like that. "Place the key in the ignition, and turn
clockwise to start the engine" is a procedure, for example.
According to the Java Language Specification, Java doesn't have
"functions" or "procedures". They have "methods".
- Oliver