I'm currently reading a book by Daniel M. Solis called "Illustrated C# 2010." The book says:
"When a method is called or invoked ..."
What is the difference between these two terms?
I'm currently reading a book by Daniel M. Solis called "Illustrated C# 2010." The book says:
"When a method is called or invoked ..."
What is the difference between these two terms?
From my research (personal & unpaid), looking at the common way these terms are used in programming literature & "in the wild", I have found that these definitions seem to fit their usages.
Execution refers to the process of running code. Exact method does not matter, can be compiled or not, done by a computer or not.
Applying/Application refers to the binding of arguments to the function. Application can be both partial and complete. From functional programming world, partial application produces another function with less parameters while complete application produces a thunk. Thunks are functions with no parameters and can help with "lazy evaluation".
Invoking/Invocation refers to the process required to schedule the function, with its fully bound arguments, for execution. Such systems include pushing arguments onto the stack and transferring the PC to the new address, placing messages/objects/functions/thunks on a queue for later execution or various other RPC systems. Exact mechanism does not matter. The notion of scheduling for future execution matters. Invoking requires that the will function execute.
Calling is the least defined out of the lot. Generally refers to the combined process of fully applying the function then invoking it, usually with the added semantic that your code will wait for a return value.
Please also note that all of these terms are subjective from the point view of the current code that is being written. Invoking a function via a RPC call is only invoking it from the client's side. From the server's side the request has a different invocation point, if the function even has any "meaning" as a function on the server's side.
Function calling is when you call a function yourself in a program. While function invoking is when it gets called automatically.
For example, consider this program:
struct s
{
int a,b,s;
s()
{
a=2;
b=3;
}
void sum()
{
s=a+b;
}
};
void main()
{
struct s obj; //line 1
obj.sum(); // line 2
}
Here, when line 1 is executed, the function (constructor, i.e. s) is invoked. When line 2 is executed, the function sum is called.
source: web
Method Invokation is a term usually refered to indirectly calling a method(function) because of problems or difficulties in calling it directly.
For example in the context of Parallel programming:Consider two threads inside one application space are running parallely. Calling a public method of an object residing on aother thread throws Cross Thread Invokation Exception because race may occure. The solution is invoking the object to execute the method and yeild the rest of job to the object to manage parallel requests.
Another example is when you have a delegate pointing to a method somewhere. When you ask the delegate to call that (unknown) method, you Invoke the method to run.
Maybe he simply considers the terms "call" and "invoke" synonymous, and just wants to mention both words because both terms can be encounter in the wild. Wouldn't it be possible to use or in that case?
When you execute the method in your code,directly, it's called Calling. When someone else executes it for you, it's Invoking. This is what I understand from Control.Invoke
method.
I don't think there're any different official definitions for both terms (in all programming fields), all different explanations are made by different developers themselves. So, I prefer to consider both terms equally.
To "invoke" appears to mean to call a method indirectly through an intermediary mechanism. I'm sure the precise meaning gets blurred by authors. But, they must be trying to describe a different way of calling a method or the term wouldn't have arisen in the first place.
Also, the general (non computer) definition of "invoke" typically means to call out to a higher power for assistance. This would translate to asking an intermediary entity for help in getting something done.
simply "call" is when guarante that the method will be tooken "invoke" is when we just ask for method to will be tooken in appropriate time
for example the main thread (GUI) can modify controls by calling but when you have another thread want to modify controls it just ask the main thread to do that when it is ready