Invocation Wizard 
Tags: codenewbie
Published: 2020-03-13 04:54:49

Going to be running with the "Rudy Wizard" idea from my last post this time. I had written about it before just as a funny aside, but the more I have been familiarizing myself with code jargon, the more I have been coming across the word "invocation". I was deeply steeped into the fantasy genre growing up so "invocation" is not a word I have seen tossed around recently. The connotations it brings up for me are quite different then what is being described to me in the steps to "invoke a method" or to "use an invocation operator", so I wanted to dig into the language and see how we got here. 

Let's start with a good ol' dictionary definition. 

invocation (n.)
* the action of invoking something or someone for assistance or as an authority.
* the summoning of a deity or the supernatural.
* an incantation used to invoke a deity or the supernatural.

If we start looking at synonyms, it gets even further away from code associations:
* bewitchment 
* charm 
* conjuration
* enchantment
* hex 
* incantation 
* spell

So right now I'm imagining all programers looking like this: 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/nrtrmy5pg6fssj5kyhve.jpg)

There are many stories of those using invocations to summon spirits or implore deities for blessings. The word appears in paganism, Christianity, voodooism, and many other religious and occult practices with references to invocations being found in cuneiform, Greek, and Egyptian, among others. A common thread, in most cases, is the summoning of something. Whether that be a demon, or a spirit, or a god, it was primarily an act of summoning something more powerful than yourself. So even though programing invocations aren't like this, 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/vh0aecxy1lu27bblm66p.png)

it's not too much of a stretch to imagine a programer calling on something more powerful than themselves, the computer, for assistance. 

Even though doing this: 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/yf86nxdy9u7e5aabdtl6.jpg)

and doing this: 

      function mathFunction(a, b) {
        return a + b;
      }

      mathFunction(4, 4);

don't feel quite the same today, a hundred years ago if you had told someone what a computer is capable of they might have also thought of it as witchcraft! 

But let's move away from witchcraft and get on to the computer magic. Like the example above, invocation in code is quite easy. Once a function or method is created, you can simply call it later, or invoke it, to run the code you have provided it. And although our mathFunction above is simple, there are much more complicated invocations out there that really do seem to be magic. Think of the "book a plane ticket" invocation or "purchase home" invocation. These complex bits of code can lead to something special, unique, or unexpected all thanks to some binary artfully crafted on a computer. 

In JavaScript, they even have something called an invocation operator. It's the "()" that is included whenever you are writing or invoking a function. This is where our expression or expressions will be placed that will correspond to an argument that can be used within the function itself. The invocation operator can include any number of expressions, including no expressions, but whenever that function is called the parenthesis must be present.  

You can also invoke a function from within an object: 

      var newObject = {
        firstName:"Harry",
        lastName: "Houdini",
        fullName: function () {
          return this.firstName + " " + this.lastName;
        }
      }

      newObject.fullName();

Our friend the invocation operator is still present in both the declaration of the function and the call of the function, but it is now part of an invocation chain off of the our object! First we invoke the object, and then the fullName function inside of it. 

So the next time you get hung up on what you're doing or lose motivation, just remember that what your are doing might as well be magic.