views:

2283

answers:

8

When verbally talking about methods in C# during a code review or in pairing I'm never sure whether to use the word argument or parameter or something else. Either way the other people know what I mean but what's correct and what's the history of the terms?

Would people use different terms in different languages?

For the record I'm self-taught without a background in Computer Science.

Please don't tell me to read Code Complete because I'm asking this for the benefit of other people who don't already have a copy of Steve McConnell's marvellous book.

[Updates:]

The general concensus seems to be that It's OK to use these terms interchangably in a team environment except perhaps when you're defining the precise terminology.

+43  A: 

Parameter is variable in the declaration of function.

Argument is the actual value of this variable that gets passed to function.

Rinat Abdullin
+8  A: 

A parameter is something you have to fill in when you call a function. What you put in it is the argument.

Simply set: the argument goes into the parameter, an argument is the value of the parameter.

A bit more info on: http://en.wikipedia.org/wiki/Parameter_(computer_science)#Parameters_and_arguments

Carra
+23  A: 

I'm not sure about this but I believe that parameter is when you write a method. When calling a method you use the term argument for the "data" you pass into the method's parameters.

public void MyMethod(string myParam) { }

...

string myArg1 = "this is my argument";
myClass.MyMethod(myArg1);

As said, I might be wrong about this... :o

Torbjörn Hansson
nice concise answer with a clear example
rohancragg
+1  A: 

The parameters of a function/method describe to you the values that it uses to calculate its result.

The arguments of a are the values assigned to these parameters during a particular call of the function/method.

Johan
+7  A: 

There is already a Wikipedia entry on the subject (see Parameter) that defines and distinguishes the terms parameter and argument. In short, a parameter is part of the function/procedure/method signature and an argument is the actual value supplied at run-time and/or call-site for the parameter.

The Wikipedia article also states that the two terms are often used synonymously (especially when reasoning about code informally):

Although parameters are also commonly referred to as arguments, arguments are more properly thought of as the actual values or references assigned to the parameter variables when the subroutine is called at runtime.

Given the following example function in C that adds two integers, x and y would be referred to as its parameters:

int add(int x, int y) {
    return x + y;
}

At a call-site using add, such as the example shown below, 123 and 456 would be referred to as the arguments of the call.

int result = add(123, 456);

Also, some language specifications (or formal documentation) choose to use parameter or argument exclusively and use adjectives like formal and actual instead to disambiguate between the two cases. For example, C/C++ documentation often refers to function parameters as formal arguments and function call arguments as actual arguments. For an example, see “Formal and Actual Arguments” in the Visual C++ Language Reference.

Atif Aziz
+2  A: 

The terms are somewhat interchangeable. The distinction described in other answers is more properly expressed with the terms formal parameter for the name used inside the body of the function and parameter for the value supplied at the call site (formal argument and argument are also common).

Also note that, in mathematics, the term argument is far more common and parameter usually means something quite different (though the parameter in a parametric equation is essentially the argument to two or more functions).

Marcelo Cantos
+1  A: 

A parameter cannot escalate into a flame war :)

pablo
+2  A: 

You can win an argument. You can never win a parameter.

James Dean
-1? Someone needs a sense of humor!
James Dean