Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between "call" and "invoke"?

Tags:

c#

terminology

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?

like image 611
John Smith Avatar asked Aug 29 '13 08:08

John Smith


People also ask

Is invoking the same as calling?

With call , you can write a method once and then inherit it in another object, without having to rewrite the method for the new object. So, the major difference between invoking and calling comes in terms of the this object. Calling let's you set the this value whereas invoking just ties it to the global object.

What does invoke a function mean?

Invoking a JavaScript Function The code inside a function is not executed when the function is defined. The code inside a function is executed when the function is invoked. It is common to use the term "call a function" instead of "invoke a function".

What does it mean to invoke a program?

The process of activating. The term invoke is usually used to refer to a routine or function in a program. Call and invoke are synonymous terms in this sense.


2 Answers

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.

like image 150
Ben Seidel Avatar answered Oct 11 '22 07:10

Ben Seidel


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

like image 27
Deep Sharma Avatar answered Oct 11 '22 05:10

Deep Sharma