Reputation: 241
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#?
Upvotes: 6
Views: 2263
Reputation: 10536
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#.
Upvotes: 4
Reputation: 11
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.
Upvotes: 1
Reputation: 3015
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.
Upvotes: 2
Reputation: 71906
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#.
Upvotes: 2
Reputation: 4278
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.
Upvotes: 0
Reputation: 8720
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"
Upvotes: 1
Reputation: 44104
I think method is the correct term, but I doubt you'll get any funny glares for using any of the other suggested names.
Upvotes: 0
Reputation: 21
I think in C# call it a method because C# is object oriented language.
Upvotes: 1