In object-oriented programming, it is said that messages are sent to methods. In this context, why is the word "method" used instead of "procedure" or "function"?
In other words, why was the word "method" introduced to programming?
In object-oriented programming, it is said that messages are sent to methods. In this context, why is the word "method" used instead of "procedure" or "function"?
In other words, why was the word "method" introduced to programming?
The name 'method' came from a philosophy of object orientation that was fundamentally about message-passing: the object model of the universe can be summed up as "there are objects; they send each other messages". Eventually, of course, there are objects that actually have some effect on the outside world, but that's a detail that's swept under the carpet in the name of uniformity.
When an object receives a message, it goes on to send further messages to other objects. Naturally, it has to have a way of deciding what messages to send - a procedure to follow, a routine to go through, or, if you like, a method to use.
You can see this usage in the Blue Book, the original description of Smalltalk-80 (this is from the first section, Classes and Instances):
An object's public properties are the messages that make up its interface. All instances of a class have the same message interface since they represent the same kind of component. An object's private properties are a set of instance variables that make up its private memory and a set of methods that describe how to carry out its operations.
The terminology is not well designed in my opinion. I believe the earliest usages talked "sending a message to an object", which at least can be pictured. Object and message were in use before method, probably with Smalltalk or earlier. I think method must have been introduced by someone who desperately wanted to divorce the method from old hat functions (or procedures). They differ slightly in the hidden nature of the implementation and the hidden instance parameter ("this").
It's simply to distinguish a function that's part of a class or object from one that isn't.
Method is used instead of procedure or function because the authors wish to maintain a distinct terminology for object-oriented programming that separates it from procedural programming.
In procedural programming your major primary units are procedures or functions.
In object oriented programming your major primary units are classes and instances (i.e. objects) of those classes. Methods only exist in the context of a class or an instance.
A rose by any other name would smell as sweet, but sometimes it helps to have a distinct name when you want to break old habits and look at things in a new way.
In the OO-Paradigma messages are send to an object. Technically this will be accomplished by invoking a method.
For more details see also: Object Oriented
In other words, why was the word "method" introduced to programming?
A method is something more than a function; as the word function was already used in programming with a specific meaning, it has been necessary to introduce a new word in the programming jargon.
For me, it just complies with common sense.
Say, you have an object; for example, a garage. Its function is to store cars, but it isn't represented by a function as a part of the object. However, the garage lives up to its function by way of methods: you drive up to the garage, press a button on your keychain (thus sending a message) and the method that lifts the door is invoked.
It is not the garage's function to lift the door, but it can do it. It's just one of the many methods that help achieve a certain goal.