Distinction between a method and a member function

Discussion in 'C++' started by Tim Martin, Aug 31, 2003.

  1. Tim Martin

    Tim Martin Guest

    Hi,

    I came across a detail in "C++ Gotchas" by Stephen Dewhurst that confused me
    a bit. The author states:

    'C++ has no "methods." Java and Smalltalk have methods. When you talk about
    an object-oriented design and are feeling particularly pretentious, you may
    use the terms "message" and "method," but when you get down to discussing a
    C++ implementation of your design, use the terms "function call" and
    "member function."'

    What he doesn't say is what the difference between a method and a member
    function is.

    Furthermore, I've looked through the C++ FAQ and the archive of this group,
    and neither mention the distinction. Quite a few posts in this group do
    seem to use the terms interchangably.

    Can anyone explain briefly what the difference is?

    Tim
     
    Tim Martin, Aug 31, 2003
    #1
    1. Advertising

  2. Tim Martin

    Sam Holden Guest

    On Sun, 31 Aug 2003 11:56:24 +0000 (UTC), Tim Martin <> wrote:
    > Hi,
    >
    > I came across a detail in "C++ Gotchas" by Stephen Dewhurst that confused me
    > a bit. The author states:
    >
    > 'C++ has no "methods." Java and Smalltalk have methods. When you talk about
    > an object-oriented design and are feeling particularly pretentious, you may
    > use the terms "message" and "method," but when you get down to discussing a
    > C++ implementation of your design, use the terms "function call" and
    > "member function."'
    >
    > What he doesn't say is what the difference between a method and a member
    > function is.
    >
    > Furthermore, I've looked through the C++ FAQ and the archive of this group,
    > and neither mention the distinction. Quite a few posts in this group do
    > seem to use the terms interchangably.
    >
    > Can anyone explain briefly what the difference is?


    There isn't any. However, in C++ the term is member function. In Java the
    term is method. Different language, different lingo.

    The C++ standard uses the term member function, and sticking with the
    convention used in a domain assists communication.

    --
    Sam Holden
     
    Sam Holden, Aug 31, 2003
    #2
    1. Advertising

  3. Tim Martin

    Jason Guest

    "Tim Martin" <> wrote in message
    news:bisnp7$a4k$...
    > Hi,
    >
    > I came across a detail in "C++ Gotchas" by Stephen Dewhurst that confused

    me
    > a bit. The author states:
    >
    > 'C++ has no "methods." Java and Smalltalk have methods. When you talk

    about
    > an object-oriented design and are feeling particularly pretentious, you

    may
    > use the terms "message" and "method," but when you get down to discussing

    a
    > C++ implementation of your design, use the terms "function call" and
    > "member function."'
    >
    > What he doesn't say is what the difference between a method and a member
    > function is.
    >
    > Furthermore, I've looked through the C++ FAQ and the archive of this

    group,
    > and neither mention the distinction. Quite a few posts in this group do
    > seem to use the terms interchangably.
    >
    > Can anyone explain briefly what the difference is?
    >
    > Tim
    >


    The author appears to be pedantic about some detail that does not really
    exist. Member functions are often used when talking about C++, but in
    reality they are all interchangeable descriptions*, and convey the notion of
    some action on an object. It is, basically a question of terminology.

    * Unless perhaps, you are talking about the differences between each
    languages' embodiment of the general theme; In that case maybe it's useful
    to use different terminology consistently.
     
    Jason, Aug 31, 2003
    #3
  4. Tim Martin

    osmium Guest

    Tim Martin writes:

    > I came across a detail in "C++ Gotchas" by Stephen Dewhurst that confused

    me
    > a bit. The author states:
    >
    > 'C++ has no "methods." Java and Smalltalk have methods. When you talk

    about
    > an object-oriented design and are feeling particularly pretentious, you

    may
    > use the terms "message" and "method," but when you get down to discussing

    a
    > C++ implementation of your design, use the terms "function call" and
    > "member function."'
    >
    > What he doesn't say is what the difference between a method and a member
    > function is.
    >
    > Furthermore, I've looked through the C++ FAQ and the archive of this

    group,
    > and neither mention the distinction. Quite a few posts in this group do
    > seem to use the terms interchangably.
    >
    > Can anyone explain briefly what the difference is?


    As far as I am concerned "method" is Smalltalk jargon and "member function"
    is C++ jargon. There is a recent,43 message thread, mostly pointless, on
    alt.comp.lang.learn.c-c++. In searching for it I noted a 125 message thread
    from a couple years ago. I suspect this was the same tempest in a teapot.
    I am using a primitive Microsoft program called Lookout Express so this link
    will probably be messed up.

    http://www.google.com/groups?hl=en&lr=lang_en&ie=UTF-8&threadm=bi38c9$9dg%
    241%40titan.btinternet.com&rnum=1&prev=/groups%3Fq%3Dmember%2Bsmalltalk%2Bgr
    oup:alt.comp.lang.learn.c-c%252B%252B%26num%3D20%26hl%3Den%26lr%3Dlang_en%26
    ie%3DUTF-8%26sa%3DG%26scoring%3Dd
     
    osmium, Aug 31, 2003
    #4
  5. osmium wrote:
    >
    > As far as I am concerned "method" is Smalltalk jargon and "member function"
    > is C++ jargon. There is a recent,43 message thread, mostly pointless, on
    > alt.comp.lang.learn.c-c++. In searching for it I noted a 125 message thread
    > from a couple years ago. I suspect this was the same tempest in a teapot.
    > I am using a primitive Microsoft program called Lookout Express so this link
    > will probably be messed up.
    >
    > http://www.google.com/groups?hl=en&lr=lang_en&ie=UTF-8&threadm=bi38c9$9dg%
    > 241%40titan.btinternet.com&rnum=1&prev=/groups%3Fq%3Dmember%2Bsmalltalk%2Bgr
    > oup:alt.comp.lang.learn.c-c%252B%252B%26num%3D20%26hl%3Den%26lr%3Dlang_en%26
    > ie%3DUTF-8%26sa%3DG%26scoring%3Dd
    >


    You can shorten those Google links a lot:

    http://www.google.com/groups?threadm=bi38c9$9dg$

    That should do it. Only the "threadm" part is important, or "selm" if
    it's a particular post, rather than a complete thread.

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
     
    Kevin Goodsell, Aug 31, 2003
    #5
  6. Tim Martin wrote:

    > I came across a detail in "C++ Gotchas" by Stephen Dewhurst
    > that confused me a bit. The author states:
    >
    > 'C++ has no "methods." Java and Smalltalk have methods.
    > When you talk about an object-oriented design
    > and are feeling particularly pretentious,
    > you may use the terms "message" and "method"
    > but when you get down to discussing a C++ implementation
    > of your design, use the terms "function call" and "member function".'
    >
    > What he doesn't say is
    > what the difference between a method and a member function is.
    >
    > Furthermore, I've looked through the C++ FAQ and the archive of this group,
    > and neither mention the distinction. Quite a few posts in this group
    > do seem to use the terms interchangeably.
    > Can anyone explain briefly what the difference is?


    The term *method* is usually reserved for the abstract description.
    When the abstract method is implemented,
    it is called a procedure, subroutine, function, operator or macro
    as is appropriate for the computer programming language in question.
    The reference to methods in the context of the Java or Smalltalk
    computer programming languages is probably abusive.
     
    E. Robert Tisdale, Sep 1, 2003
    #6
  7. Tim Martin

    llewelly Guest

    Tim Martin <> writes:

    > Hi,
    >
    > I came across a detail in "C++ Gotchas" by Stephen Dewhurst that confused me
    > a bit. The author states:
    >
    > 'C++ has no "methods." Java and Smalltalk have methods. When you talk about
    > an object-oriented design and are feeling particularly pretentious, you may
    > use the terms "message" and "method," but when you get down to discussing a
    > C++ implementation of your design, use the terms "function call" and
    > "member function."'
    >
    > What he doesn't say is what the difference between a method and a member
    > function is.
    >
    > Furthermore, I've looked through the C++ FAQ and the archive of this group,
    > and neither mention the distinction. Quite a few posts in this group do
    > seem to use the terms interchangably.
    >
    > Can anyone explain briefly what the difference is?


    Sometimes the term 'method' is used to indicate any operation on an
    object. In C++ many operation should not be member functions,
    e.g. operators like +, *, ==, and so on.
     
    llewelly, Sep 1, 2003
    #7
  8. llewelly wrote:

    > In C++ many operation should not be member functions,
    > e.g. operators like +, *, ==, and so on.


    Nonsense!
     
    E. Robert Tisdale, Sep 1, 2003
    #8
  9. "E. Robert Tisdale" <> wrote in message
    news:...
    > Tim Martin wrote:
    >
    > > Can anyone explain briefly what the difference is?

    >
    > The term *method* is usually reserved for the abstract description.
    > When the abstract method is implemented,
    > it is called a procedure, subroutine, function, operator or macro
    > as is appropriate for the computer programming language in question.
    > The reference to methods in the context of the Java or Smalltalk
    > computer programming languages is probably abusive.


    Nah. What is refered to as a member function in C++ IS a method in Java.
    Just a different name.
    A simple function is not a member of a class. There is no equivalent in
    Java.
    It's just different names.
    --
    Gary
     
    Gary Labowitz, Sep 1, 2003
    #9
  10. Tim Martin

    jeffc Guest

    "Tim Martin" <> wrote in message
    news:bisnp7$a4k$...
    > Hi,
    >
    > I came across a detail in "C++ Gotchas" by Stephen Dewhurst that confused

    me
    > a bit. The author states:
    >
    > 'C++ has no "methods." Java and Smalltalk have methods. When you talk

    about
    > an object-oriented design and are feeling particularly pretentious, you

    may
    > use the terms "message" and "method," but when you get down to discussing

    a
    > C++ implementation of your design, use the terms "function call" and
    > "member function."'
    >
    > What he doesn't say is what the difference between a method and a member
    > function is.


    Frankly, he's the one that sounds a bit pretentious. Assuming you are
    writing OO code in C++, then using both the language of OO design and the
    language of C++ implementation are valid. It doesn't make sense to be
    pedantic and point out every time you make a comment that you're in the "OO
    realm" or "C++ realm" at the moment. It's not pretentious at all to say
    "message" or "method" when discussing a design implemented in C++. If there
    is a difference between "method" and "function" in the context about which
    I'm speaking, it would be that "method" is more abstract - in the OO sense -
    and "function" is more concrete - in the C++ implementation sense.
     
    jeffc, Sep 2, 2003
    #10
  11. Tim Martin

    jeffc Guest

    jeffc, Sep 2, 2003
    #11
  12. jeffc wrote:

    > It's not pretentious at all to say
    > "message" or "method" when discussing a design implemented in C++.


    I think that it is pretentious.
     
    E. Robert Tisdale, Sep 2, 2003
    #12
  13. Tim Martin

    llewelly Guest

    "E. Robert Tisdale" <> writes:

    > llewelly wrote:
    >
    >> In C++ many operation should not be member functions,
    >> e.g. operators like +, *, ==, and so on.

    >
    > Nonsense!


    Problem #0 Uncessary access. For example:

    struct my_complex
    {
    double real()const{return real_;}
    double imaginary()const{return imaginary_;}
    private:
    double real_, imaginary_;
    };

    With this interface, nonassignment operators need no access, and
    therefor should not have it.

    Problem #1 Member functions are not compatible with non-member
    functions, and the standard C++ library treats member functions as
    second class citizens, requiring use of std::mem_fun, or
    boost::mem_fn, niether of which correctly handles all cases.

    #include<algorithm>

    struct my_int
    {
    my_int():value(0){}
    explicit my_int(int value):value(value){}
    bool operator>(my_int rhs)const{return value > rhs.value;}
    private:
    int value;
    };

    int main()
    {
    int const size= 10;
    my_int a[size];
    //... fill a.
    std::sort(a, a+size, &my_int::eek:perator>);
    }

    Does not compile. Rewrite operator> as a non-member:

    struct my_int
    {
    my_int():value(0){}
    explicit my_int(int value):value(value){}
    friend bool operator>(my_int lhs,my_int rhs){return lhs.value > rhs.value;}
    private:
    int value;
    };

    int main()
    {
    int const size= 10;
    my_int a[size];
    //... fill a.
    std::sort(a, a+size, &operator>); //compiles easily.
    }

    This example could also be 'fixed' using mem_fun, but others using
    binders cannot. Some (but not all!) examples using binders can
    be fixed with boost::bind or boost::mem_fn .

    Problem #2 Overloading rules do not apply implicit conversions for the
    left hand operator.

    struct my_int
    {
    my_int():value(0){}
    my_int(int value):value(value){}
    my_int operator+(my_int rhs)const{return value + rhs.value;}
    private:
    int value;
    };

    int main()
    {
    my_int a;
    int b;
    my_int c= a + b; //compiles.
    my_int d= b + a; //does not compile.
    }

    I say it is nonsense to implement operator+ so that a + b compiles but
    b + a does not. The work-arounds? (a) do without the implicit
    conversion, and (b), implement more overloads of operator+, some
    of which *must* be non-members, because the left-hand operand
    must be of a type other than my_int.

    Problem #3 The oft-posted mistake:

    struct my_int
    {
    my_int operator+(my_int rhs){return value + rhs.value;}
    private:
    int value;
    };

    Did you catch it? const, where necessary, more easily remembered, (and
    more easily noticed missing) in the parameter list.

    There are more problems with member functions, but they are mostly
    minor.
     
    llewelly, Sep 3, 2003
    #13
  14. Tim Martin

    Howie Guest

    I just thought:

    a method is like a "function" but without a return value.

    a function is like a "method" but with a return value.


    void ThisIsAMethod(.....);


    long ThisIsAFunction(....)


    Greetings,
    Howie
     
    Howie, Sep 3, 2003
    #14
  15. Tim Martin

    jeffc Guest

    "E. Robert Tisdale" <> wrote in message
    news:...
    > jeffc wrote:
    >
    > > It's not pretentious at all to say
    > > "message" or "method" when discussing a design implemented in C++.

    >
    > I think that it is pretentious.


    Then I guess you think discussing anything in OO design terms rather than
    C++ terms is "pretentious"? That's silly.
     
    jeffc, Sep 3, 2003
    #15
  16. Howie escribiĆ³:

    > a method is like a "function" but without a return value.


    That thing is called "procedure" in languages that makes the difference.

    Regards.
     
    =?iso-8859-1?Q?Juli=E1n?= Albo, Sep 3, 2003
    #16
  17. Howie wrote:
    > I just thought:
    >
    > a method is like a "function" but without a return value.


    In some languages that would be a 'procedure'. I've never heard it
    called a 'method' before.

    In any case, C++ has functions. Whether they return a value or not,
    whether they are a member or not, they are always called functions.
    That's just the way the language has always been described.

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
     
    Kevin Goodsell, Sep 3, 2003
    #17
  18. Tim Martin

    White Wolf Guest

    Tim Martin wrote:
    > Hi,
    >
    > I came across a detail in "C++ Gotchas" by Stephen Dewhurst that
    > confused me a bit. The author states:
    >
    > 'C++ has no "methods." Java and Smalltalk have methods. When you talk
    > about an object-oriented design and are feeling particularly
    > pretentious, you may use the terms "message" and "method," but when
    > you get down to discussing a C++ implementation of your design, use
    > the terms "function call" and "member function."'
    >
    > What he doesn't say is what the difference between a method and a
    > member function is.
    >
    > Furthermore, I've looked through the C++ FAQ and the archive of this
    > group, and neither mention the distinction. Quite a few posts in this
    > group do seem to use the terms interchangably.
    >
    > Can anyone explain briefly what the difference is?


    The difference is that method is an OO term and there is no well defined
    meaning for in when you talk about C++. Some understands it as any member
    function. Some others understand it only as virtual member functions. In
    fact - if we take the original OO meaning - non-member operator functions
    (found by ADL) should also be called methods in C++, since they *are* part
    of the classes interface, they just happen to be implemented as a non-member
    function for technical reasons.

    C++ really has no methods. It is a terminology aspect. Since what methods
    mean in a C++ implementation context might be ambiguous it helps if this
    term is not used in that context. Of course this is not a law, it is just
    common sense: helps to avoid misunderstandings. For example if you ask the
    question: what methods does C++ generate automaticly? some might answer:
    none. Since while you have meant "member functions" when saying "method"
    those answering meant "virtual member functions" when they have read
    "methods".

    --
    WW aka Attila
     
    White Wolf, Sep 3, 2003
    #18
  19. Tim Martin

    Ron Natalie Guest

    "Kevin Goodsell" <> wrote in message news:3f560be1@shknews01...
    > Howie wrote:
    > > I just thought:
    > >
    > > a method is like a "function" but without a return value.

    >
    > In some languages that would be a 'procedure'. I've never heard it
    > called a 'method' before.
    >

    The common computer science definition of a method is an action performed
    on an object. Therefore, they are usually implemented in C++ as non-static
    member functions, although not all member functions in C++ are used as methods.

    Anyhow, the term is outside the C++ language.
     
    Ron Natalie, Sep 3, 2003
    #19
  20. Howie <> wrote in message news:<>...

    > a method is like a "function" but without a return value.


    You're probably thinking "subroutine" or "procedure." "method" is most
    definitely an OOP term, most properly associated with virtual
    functions in C++ (although it is occasionally [perhaps erroneously]
    used to describe non-virtual, non-static member functions as well):

    <http://www.nightflight.com/foldoc-bin/foldoc.cgi?method>
    <http://www.nightflight.com/foldoc-bin/foldoc.cgi?subroutine>

    - Shane
     
    Shane Beasley, Sep 3, 2003
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Casey Hawthorne
    Replies:
    4
    Views:
    361
    Casey Hawthorne
    Oct 20, 2005
  2. Ishwor

    distinction between float & int

    Ishwor, Dec 3, 2004, in forum: Python
    Replies:
    1
    Views:
    279
    Steve Holden
    Dec 3, 2004
  3. webcomm
    Replies:
    10
    Views:
    737
    John Machin
    Jan 10, 2009
  4. Uday S Reddy
    Replies:
    0
    Views:
    88
    Uday S Reddy
    Apr 17, 2013
  5. Andreas Abel
    Replies:
    0
    Views:
    112
    Andreas Abel
    Apr 17, 2013
Loading...

Share This Page