Each language has its own lexicon of terms with special meaning. In "C", the word "function" means a program routine.
In Java, the term "function" does not have any special meaning. Whereas "method" means one of the routines that forms the implementation of a class.
If you use the term "function" in informal discussions about Java, people will assume you meant "method" and carry on. Don't use it in proper documents or presentations about Java, or you will look silly.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
A "method" is a "member function" - a function that is embedded in a class. In some languages, such as C++, you can also have standalone functions -functions that don't belong to any class.
At least that's the terminology that I'm used to.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I generally think of a function as being in a non OO program- it is just a block of code that needs to be executed multiple times, and it is most convenient to put it into one nice little name that you can call from anywhere in the file. I generally think of a method as being inside a class, and is not a convenience but a necessity: everything is in a method. This is why I consider Java and C++ to use methods, and languages such as AS and BASIC to use functions. Also, functions are generally declared with the word 'function.'
Users of functional programming languages (not to be confused with programming languages who's subroutines are colloquially called "functions") tend to think of a function f as a mapping from X to Y (f(X) = Y). Importantly a function will always return the same result when called with the same arguments. By that definition a java method like java.lang.StringBuilder.append(char) is not a function but java.util.Arrays.binarySearch(int,int) is. [ June 04, 2008: Message edited by: Garrett Rowe ]
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Joined: Jul 11, 2001
Originally posted by Garrett Rowe: Importantly a function will always return the same result when called with the same arguments.
That indicates the main thing to learn from this thread. That is, particular words have different meanings, or no particular meaning at all, depending on what type of programming you're talking about. So it is important to make clear the context of the discussion.
In Java "function" doesn't mean anything special. In C, "function" means a program routine. In C++, it can mean the same as it does in C, or it can mean rather the same as "method" does in Java. In functional programming, a "function" has a very strict definition, much tighter than in the procedural/OO languages previously mentioned.