4

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?

4
  • 5
    This question might be better suited for SO or programmers.stackexchange. I suspect the answer is more 'techie' related than language related.
    – oosterwal
    Commented Feb 26, 2011 at 5:01
  • 1
    @oosterwal: you're probably right; the fact that English words are typically used for the terminology is pretty much incidental.
    – mgkrebbs
    Commented Feb 26, 2011 at 5:09
  • 2
    I haven't come across messages being sent to methods, only objects. I believe you are describing an incorrect use. May i ask where you encountered this? Commented Feb 26, 2011 at 20:04
  • Tom, I agree it is probably a misuse but the question is really about use of the word method.
    – H2ONaCl
    Commented Jul 20, 2011 at 0:50

7 Answers 7

5

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.

3

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").

2
  • 2
    If the marketing push was for object oriented programming as a new paradigm in opposition to functional programming or procedural programming then you do not want functions or procedures to be key parts of the lexicon.
    – Henry
    Commented Feb 26, 2011 at 9:47
  • In correct use, one still sends a message to an object; the object handles it using a method. Commented Feb 26, 2011 at 20:06
3

It's simply to distinguish a function that's part of a class or object from one that isn't.

3

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.

2
  • In functional programming your primary units are functions as well. Take a look at Javascript, for example. Functional programming is what makes map/reduce algorithms possible. See Joel Spolsky's article on this topic.
    – Robusto
    Commented Feb 26, 2011 at 12:25
  • 1
    @Robusto, not strictly true. Map/fold is possible in OO languages. The relevance of functional languages to map/fold is that they are more natural and more central to the idiomatic ways of using those languages. Commented Feb 26, 2011 at 21:36
2

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

-1

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.

-1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.