CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

View Poll Results: How do you call void foo()

Voters
9. You may not vote on this poll
  • Method

    0 0%
  • Function

    9 100.00%
Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    Join Date
    Nov 2003
    Posts
    1,405

    Re: What void foo() is really? - a Method? OR a Function?

    Quote Originally Posted by laserlight View Post
    However, that does not really answer thomus07's question: "what factor separates a method and a function"?
    The decisive factor is how the function is used. If it defines object behaviour it's a method (according to the OO terminology).

    In my view in C++ it's questionable whether static functions and private function should be called methods. In Java they are but that's probably only because every function is called a method there.

  2. #17
    Join Date
    Nov 2003
    Posts
    1,405

    Re: What void foo() is really? - a Method? OR a Function?

    Add this choise to the poll,

    - Method if it defines object behaviour, otherwise function.

  3. #18
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: What void foo() is really? - a Method? OR a Function?

    Quote Originally Posted by _uj
    The decisive factor is how the function is used. If it defines object behaviour it's a method (according to the OO terminology).
    What does "defines object behaviour" really mean?

    Quote Originally Posted by _uj
    In Java they are but that's probably only because every function is called a method there.
    Yes, the term would be language specific in that context.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  4. #19
    Join Date
    Mar 2007
    Posts
    155

    Re: What void foo() is really? - a Method? OR a Function?

    Quote Originally Posted by _uj View Post
    Add this choise to the poll,

    - Method if it defines object behaviour, otherwise function.
    Thanks _uj. All your answers are very informative.
    The poll is not a judgment of What void foo() - is a Method? or Function?
    It is what we are discussing.

    The poll is about - How do you call / refer to void foo() in all our C++ programming career. In the sense some people call it as method and some as function.

    Because modern languages like C#, refers as "Method". Even in this perspective static methods won't define object's behavior. Still C# calls everything as Method.

    So I think it is more towards - A LANGUAGE PERSPECTIVE than the actual concept.

  5. #20
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: What void foo() is really? - a Method? OR a Function?

    Quote Originally Posted by thomus07
    The poll is about - How do you call / refer to void foo() in all our C++ programming career. In the sense some people call it as method and some as function.

    Because modern languages like C#, refers as "Method". Even in this perspective static methods won't define object's behavior. Still C# calls everything as Method.

    So I think it is more towards - A LANGUAGE PERSPECTIVE than the actual concept.
    "When in Rome, do as the Romans do."

    Therefore, I would suggest that you call foo a "function", not a "method", in C++. However, if you are discussing such constructs with a group of programmers more familiar or comfortable with the term "method", by all means use "method".
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  6. #21
    Join Date
    Mar 2007
    Posts
    155

    Re: What void foo() is really? - a Method? OR a Function?

    Quote Originally Posted by laserlight View Post
    "When in Rome, do as the Romans do."

    Therefore, I would suggest that you call foo a "function", not a "method", in C++. However, if you are discussing such constructs with a group of programmers more familiar or comfortable with the term "method", by all means use "method".
    Thanks Laserlight.
    This is very good practical suggestion even though it's fool proof.

  7. #22
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: What void foo() is really? - a Method? OR a Function?

    If we consider that "function" in most programming languages indicates a block of callable code [although some do restrict it to those cases that return a value].....Then we consider "method" to mean "behaviour".

    We begin to see where Stroustrup's selectionof virtual functions to be called methods makes alot of sense.

    static members and non-virtual instance members have a definite 1:1 mapping to a specific block of code. This code can be called a "function" if you accept my first paragraph.

    virtual members on the other hand, truely do specify a behaviour, which can be abstract (pure), have a single implementation (no-overrides) or multiple implementations (overrides in different derived classses).

    Therefore you can NOT say "a virtual member is a function" (note the emphasis on the singular).
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  8. #23
    Join Date
    Mar 2007
    Posts
    155

    Re: What void foo() is really? - a Method? OR a Function?

    Quote Originally Posted by TheCPUWizard View Post
    ............................
    static members and non-virtual instance members have a definite 1:1 mapping to a specific block of code. This code can be called a "function" if you accept my first paragraph.
    .................................
    Thanks cpuwizard.
    Your analysis are very excellent.
    You could say some valid points to support non-virtual members as functions.

    I think most languages refer either of the way. And it is advised to adopt consistently for that language.
    This may be because this couldn't create any side effect.

    A deep analysis could say that, in some contexts this generalization is not suitable.
    To refer correct name in appropriate context will make correct sense undoubtedly. Also correct reference gives a better understanding of the language.
    If we don't want if we can forget this may be .

  9. #24
    Join Date
    Apr 2004
    Posts
    102

    Re: What void foo() is really? - a Method? OR a Function?

    No matter how many times I've heard these arguments, I've come to the conclusion that a function vs. a method is really is only a symantac difference. Heck, if you ported it to Pascal it would be a Procedure. My advice, roll with whatever term the language calls it (or whatever your instructor calls it, for the duration you are in his/her class).

    just for kicks:
    Code:
    {Pascal version of foo, not case sensitive}
    Procedure foo;
    begin
    end;
    
    {variation with parameters}
    Procedure foo2(someValue: Integer);
    begin
    	someValue:=someValue+1;
    end;
    
    {variation as a Function}
    Function foo3(someValue: Integer): Integer;
    begin
    	foo3:=someValue*3;
    end;
    Last edited by jefranki; January 5th, 2009 at 04:53 PM. Reason: missed a couple semi-colons, grammar clean-up

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured