tags:

views:

157

answers:

9

consider a standard c# 'function'

public void foo() { //some code }

In c or c++ this is called a 'function' - even if taking no parameters and returning no value. In another language maybe it would be a 'procedure'. In object orientation speak it would be called a 'method' if a class member. What would be the correct term to use in c#?

+1  A: 

I think in C# call it a method because C# is object oriented language.

tanakorn
What about a JavaScript function? Should we call it a method too?
sahs
A: 

I think method is the correct term, but I doubt you'll get any funny glares for using any of the other suggested names.

Kendall Hopkins
+1  A: 

If a "Function" is part of a class I call it a method.

If I was coding in C (i.e. in proceedural or non OO idiom) I call it a function.

I personally don't use the word proceedure to refer to a "Function"

David Relihan
A: 

Since I spent a lot of time with ADA I would call that a "procedure" since it has no return value. If it had a return value, I would have called it a "function".

I've never seen the point of saying "Method", though that is most likely the correct term to use when talking about functions/procedures that are members of a class. Never really saw the use of yet another term for the same thing.

wasatz
+4  A: 
  • Method : function of a class.
  • Function : function out of a class, possible only in full-object languages (like C++, C, etc.)
  • Procedure : function that return nothing/void. I personnaly don't like this word, I'd rather use 'function'

Make your choice =)

Edit : Just to be more precise, Method, function and procedure are OOP words to describe a subroutine. Some languages have their own vocabulary such as "predicate" in Prolog, or "constructor" in C++/C#/Java, or even "property" in C#.

Clement Herreman
A Prolog predicate is far from a subroutine. Languages with subroutines, Algol derivatives, consist of imperative statements plus expressions. I would opine that a language without statements cannot have subroutines, even though it can have functions. Is "y = 2 *x + b" a subroutine? A function? ;)
Heath Hunnicutt
@Heath you're right, especially for the Prolog. I guess subroutine isn't appropriated. I might edit to deleted it..
Clement Herreman
+2  A: 

Just to confuse the issue futher: (from C# Language Specification)

7.4 Function members
Function members are members that contain executable statements. Function members are always members of types and cannot be members of namespaces. C# defines the following categories of function members:
* Methods
* Properties
* Events
* Indexers
* User-defined operators
* Instance constructors
* Static constructors
* Destructors

And

10. Classes
A class is a data structure that may contain data members (constants and fields), function members (methods, properties, events, indexers, operators, instance constructors, destructors and static constructors), and nested types. Class types support inheritance, a mechanism whereby a derived class can extend and specialize a base class.

So "function member" or "method" would be correct for C#.

Cameron MacFarland
+2  A: 

Method is OOP abstraction term. They describe behaviour(a verb) of an object. They are equivalent to some of the procedural programming's functions and procedures. (the properties etc are also function and procedures).

So, function is a program within program that returns some values. Procedure is a program within program that does something. Methods, Properties etc, etc are a next level of abstraction(used in OOP). They are wrapped around functions and procedures.

Mike
+1  A: 

I thought (in Ada) that a 'procedure' is the correct term generally, and a 'function' is a procedure which is guaranteed to be side-effect free, that is, it only reads from and does manipulation on data, and returns it, but does not write anything or have any 'side-effects'.

I'm a Java guy anyway, I call everything a function even though it should be called a method.

John
A: 

outside of C or C++, it makes little sense to call methods «member function»; people seem to use «method» for class methods nowadays. «Procedure» is largely a historical term now, it made sense to use it to refer to void functions in C/C++, but since functions that return nothing are a now generally accepted to be a Bad Idea, I use «procedure» only when discussing approaches and other meta stuff; actual code forms that do something are most frequently «functions» and «methods». While «method» is a methodologic notion rather than a technical description of a class member function, it seems that everyone calls those «method» anyway.

d.Candela