I always thought call-by-value and pass-by-value were synonymous. However, I recently heard someone refer to them as if they were different. Are they the same thing?
I'm also talking about their corresponding by-reference terms too.
I always thought call-by-value and pass-by-value were synonymous. However, I recently heard someone refer to them as if they were different. Are they the same thing?
I'm also talking about their corresponding by-reference terms too.
Yes those terms are synonyms as I understand them.
However, I think you are asking the wrong audience. If your colleague regards them as different, then you and they have a mismatch of understanding. Whether or not I think they are the same is irrelevant, what counts is what your colleague actually means.
"Someone," is wrong. Check out the Wikipedia article which directly answers your question. You can point that certain "someone" at this article, as well:
Call-by-value evaluation (also referred to as pass-by-value) is the most common evaluation strategy, ...
They are synonymous. The term call-by-value means exactly the same as pass-by-value.
However, I prefer the pass-by-value form, as it's the parameter that is passed that it refers to. A call can have parameters that are passed by value as well as parameters passed by reference.
Example:
public void Something(string name, int count, ref string target, ref int result)
The first parameter is a reference passed by value, the second is a value passed by value, the third is a reference passed by reference, and the fourth is a value passed by reference.
I've always considered them synonymous, but when I think about it, perhaps they're trying to differentiate between calling a method directly and calling a method through a reference (i.e. a delegate). That is, given this:
public delegate void MyDelegate();
class MyClass
{
public void DoSomething()
{
// ...
}
}
MyClass thing = new MyClass();
Are they trying to say that if you write:
thing.DoSomething();
Then it's a "call by value", but if you write:
MyDelegate dlgt = thing.DoSomething;
dlgt(); // calls thing.DoSomething through the delegate reference
then it's a "call by reference?"
They are synomynous.
"call" means the method, and "pass" means an(the) argument(s).
Example: