View Poll Results: How do you call void foo()
- Voters
- 9. You may not vote on this poll
-
January 5th, 2009, 04:32 AM
#16
Re: What void foo() is really? - a Method? OR a Function?
 Originally Posted by laserlight
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.
-
January 5th, 2009, 04:37 AM
#17
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.
-
January 5th, 2009, 04:51 AM
#18
Re: What void foo() is really? - a Method? OR a Function?
 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?
 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.
-
January 5th, 2009, 04:54 AM
#19
Re: What void foo() is really? - a Method? OR a Function?
 Originally Posted by _uj
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.
-
January 5th, 2009, 05:05 AM
#20
Re: What void foo() is really? - a Method? OR a Function?
 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".
-
January 5th, 2009, 05:13 AM
#21
Re: What void foo() is really? - a Method? OR a Function?
 Originally Posted by laserlight
"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.
-
January 5th, 2009, 07:20 AM
#22
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
-
January 5th, 2009, 11:38 AM
#23
Re: What void foo() is really? - a Method? OR a Function?
 Originally Posted by TheCPUWizard
............................
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 .
-
January 5th, 2009, 01:11 PM
#24
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|